Beruflich Dokumente
Kultur Dokumente
1. Uptime Command
In Linux uptime command shows since how long your system is running and the number of users are
currently logged in and also displays load average for 1,5 and 15 minutes intervals.
# uptime
08:16:26 up 22 min, 1 user, load average: 0.00, 0.03, 0.22
2. W Command
It will displays users currently logged in and their process along-with shows load averages. also shows
the login name, tty name, remote host, login time, idle time, JCPU, PCPU, command and
processes.
# w
08:27:44 up 34 min, 1 user, load average: 0.00, 0.00, 0.08
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
tecmint pts/0 192.168.50.1 07:59 0.00s 0.29s 0.09s w
Available options
1. -h : displays no header entries.
2. -s : without JCPU and PCPU.
3. -f : Removes from field.
4. -V : (upper letter) Shows versions.
3. Users Command
Users command displays currently logged in users. This command dont have other parameters other
than help and version.
# users
tecmint
4. Who Command
who command simply return user name, date, time and host information. who command is similar to
w command. Unlike w command who doesnt print what users are doing. Lets illustrate and see the
different between who and w commands.
# who
tecmint pts/0 2012-09-18 07:59 (192.168.50.1)
# w
08:43:58 up 50 min, 1 user, load average: 0.64, 0.18, 0.06
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
tecmint pts/0 192.168.50.1 07:59 0.00s 0.43s 0.10s w
5. Whoami Command
whoami command print the name of current user. You can also use who am i command to display
the current user. If you are logged in as a root using sudo command whoami command return root as
current user. Use who am i command if you want to know the exact user logged in.
# whoami
tecmint
6. ls Command
ls command display list of files in human readable format.
# ls -l
total 114
dr-xr-xr-x. 2 root root 4096 Sep 18 08:46 bin
dr-xr-xr-x. 5 root root 1024 Sep 8 15:49 boot
For more examples of ls command, please check out our article on 15 Basic ls Command Examples in
Linux.
7. Crontab Command
List schedule jobs for current user with crontab command and -l option.
# crontab -l
00 10 * * * /bin/ls >/ls.txt
Edit your crontab with -e option. In the below example will open schedule jobs in VI editor. Make a
necessary changes and quit pressing :wq keys which saves the setting automatically.
# crontab -e
For more examples of Linux Cron Command, please read our earlier article on 11 Cron Scheduling
Task Examples in Linux.
8. Less Command
less command allows quickly view file. You can page up and down. Press q to quit from less window.
# less install.log
Installing setup-2.8.14-10.el6.noarch
warning: setup-2.8.14-10.el6.noarch: Header V3 RSA/SHA256 Signature, key ID
c105b9de: NOKEY
Installing filesystem-2.4.30-2.1.el6.i686
Installing ca-certificates-2010.63-3.el6.noarch
Installing xml-common-0.6.3-32.el6.noarch
Installing tzdata-2010l-1.el6.noarch
Installing iso-codes-3.16-2.el6.noarch
9. More Command
more command allows quickly view file and shows details in percentage. You can page up and down.
Press q to quit out from more window.
# more install.log
Installing setup-2.8.14-10.el6.noarch
warning: setup-2.8.14-10.el6.noarch: Header V3 RSA/SHA256 Signature, key ID
c105b9de: NOKEY
Installing filesystem-2.4.30-2.1.el6.i686
Installing ca-certificates-2010.63-3.el6.noarch
Installing xml-common-0.6.3-32.el6.noarch
Installing tzdata-2010l-1.el6.noarch
Installing iso-codes-3.16-2.el6.noarch
--More--(10%)
10. CP Command
Copy file from source to destination preserving same mode.
# cp -p fileA fileB
11. MV Command
Rename fileA to fileB. -i options prompt before overwrite. Ask for confirmation if exist already.
# mv -i fileA fileB
You combine more and less command with cat command to view file contain if that doesnt fit in
single screen / page.
# cat install.log | less
# cat install.log | more
For more examples of Linux cat command read our article on 13 Basic Cat Command Examples in
Linux.
16. VI Command
Vi is a most popular text editor available most of the UNIX-like OS. Below examples open file in read
only with -R option. Press :q to quit from vi window.
# vi -R /etc/shadows
Putting multiple files in remote host with mput similarly we can do mget to download multiple files
from remote host.
# ftp > mput *.txt
# ftp > mget *.txt
Free with -t options shows total memory used and available to use in bytes.
# free -t
total used free shared buffers cached
Mem: 1030800 736096 294704 0 51720 547704
-/+ buffers/cache: 136672 894128
Swap: 2064376 0 2064376
Total: 3095176 736096 2359080
For more about top command weve already compiled a list of 12 TOP Command Examples in Linux.
To understand more about tar command weve created a complete how-to guide on tar command at
18 Tar Command Examples in Linux.
For complete guide on Linux find command examples fount at 35 Practical Examples of Linux Find
Command.
25. lsof Command
lsof mean List of all open files. Below lsof command list of all opened files by user tecmint.
# lsof -u tecmint
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 1889 tecmint cwd DIR 253,0 4096 2 /
sshd 1889 tecmint txt REG 253,0 532336 298069 /usr/sbin/sshd
sshd 1889 tecmint DEL REG 253,0 412940 /lib/libcom_err.so.2.1
sshd 1889 tecmint DEL REG 253,0 393156 /lib/ld-2.12.so
sshd 1889 tecmint DEL REG 253,0 298643
/usr/lib/libcrypto.so.1.0.0
sshd 1889 tecmint DEL REG 253,0 393173 /lib/libnsl-2.12.so
sshd 1889 tecmint DEL REG 253,0 412937
/lib/libkrb5support.so.0.1
sshd 1889 tecmint DEL REG 253,0 412961 /lib/libplc4.so
For more lsof command examples visit 10 lsof Command Examples in Linux.
You can use last with username to know for specific users activity as shown below.
# last tecmint
tecmint pts/1 192.168.50.1 Tue Sep 18 08:50 still logged in
tecmint pts/0 192.168.50.1 Tue Sep 18 07:59 still logged in
tecmint pts/1 192.168.50.1 Thu Sep 13 08:07 - down (01:15)
tecmint pts/4 192.168.50.1 Wed Sep 12 10:12 - 12:29 (02:17)
27. ps command
ps command displays about processes running in the system. Below example show init process only.
# ps -ef | grep init
root 1 0 0 07:53 ? 00:00:04 /sbin/init
root 7508 6825 0 11:48 pts/1 00:00:00 grep init
29. rm command
rm command used to remove or delete a file without prompting for confirmation.
# rm filename
Using -i option to get confirmation before removing it. Using options -r and -f will remove the file
forcefully without confirmation.
# rm -i test.txt
rm: remove regular file `test.txt'?
This is a handy day to day useable basic commands in Linux / Unix-like operating system. Kindly
share through our comment box if we missed out
2.Pre-requisites
CentOS 6.6: Lesson 1: Installing CentOS 6.6
3. Lab Notes
In this lab we will do the following:
1. Determine who the current user is after switching
user.
2. Determine who the current user was before switching
user.
3. Learning how to create, rename and delete files.
4. Learning how to view files.
4.Legal Disclaimer
As a condition of your use of this Web site, you warrant to
computersecuritystudent.com that you will not use this Web
site for any purpose that is unlawful or that is prohibited
by these terms, conditions, and notices.
In accordance with UCC 2-316, this product is provided
with "no warranties, either express or implied." The
information contained is provided "as-is", with "no
guarantee of merchantability."
In addition, this is a teaching website that does not
condone malicious behavior of any kind.
You are on notice, that continuing and/or using this lab
outside your "own" test environment is considered malicious
and is against the law.
2015 No content replication of any kind is allowed
without express written permission.
2.Open a Terminal
Instructions:
1. Applications --> System Tools --> Terminal
3.Switch User to root
Instruction:
1. su - root
2. Supply the Root Password
Notes (FYI):
1. su - root, this command allows the user student to
switch user to user root, provided the root password
can be supplied.
4.Get IP Address
Instructions:
1. ifconfig -a
Notes (FYI):
1.As indicated below, my IP address is 192.168.1.101 for
Network Interface eth1.
Please record your IP address
2.The Local Loopback Address is 127.0.0.1 for Network
Interface lo.
The loopback device is a special, virtual network interface
that your computer uses to communicate with itself. When
the network or wifi is disconnected the loopback exists so
applications running on your computer can always connect
to servers on the same machine.
3.Opening a file with gedit
Instructions:
1. gedit /var/tmp/etc/passwd_file 2>/dev/null
2. Click "X" to close gedit
Note(FYI):
1.gedit, is the gnome text editor.
Section 9. Copying, Moving and Deleting Files
1.Opening a file with gedit
Instructions:
1. cd /var/tmp/etc
2. ls -l
3. cp passwd_file2 passwd_file4
4. mv passwd_file4 passwd_file3
5. ls -l
Note(FYI):
1. cd /var/tmp/etc, Change directory into /var/tmp/etc.
2. ls -l, List the files in the /var/tmp/etc directory.
3. cp passwd_file2 passwd_file4, use the copy command
(cp) to copy file passwd_file2 and name the new file
passwd_file4.
4. mv passwd_file4 passwd_file3, use the move/rename
command (mv)to rename passwd_file4 to passwd_file3.
5. ls -l, List the files in the /var/tmp/etc directory.
2.Opening a file with gedit
Instructions:
1. cp passwd_file3 passwd_file5
2. ls -l passwd_file*
3. rm passwd_file5
4. y
5. ls -l passwd_file*
Note(FYI):
1. cp passwd_file3 passwd_file5, use the copy command
(cp) to copy file passwd_file3 and name the new file
passwd_file5.
2. ls -l passwd_file*, In the /var/tmp/etc directory,
list all the files that start with the string
passwd_file. The asterisk(*) is a wild card.
3. rm passwd_file5, use the remove/delete command (rm)to
delete the passwd_file5 file.
4. If you do not use the (-f) option with the rm command,
then you will prompted to re-verify the deletion of a
file.
5. See comment #2.
ommand Description
Display files contents to the standard output device
cat [filename]
(usually your monitor).
cd /directorypath Change to directory.
chmod [options] mode filename Change a files permissions.
chown [options] filename Change who owns a file.
clear Clear a command line screen/window for a fresh start.
cp [options] source destination Copy files and directories.
date [options] Display or set the system date and time.
df [options] Display used and available disk space.
du [options] Show how much space each file takes up.
file [options] filename Determine what type of data is within a file.
find [pathname] [expression] Search for files matching a provided pattern.
grep [options] pattern [filesname] Search files or output for a particular pattern.
kill [options] pid Stop a process. If the process refuses to stop, use kill -9 pid.
less [options] [filename] View the contents of a file one page at a time.
ln [options] source [destination] Create a shortcut.
Search a copy of your filesystem for the specified
locate filename
filename.
lpr [options] Send a print job.
ls [options] List directory contents.
man [command] Display the help information for the specified command.
mkdir [options] directory Create a new directory.
mv [options] source destination Rename or move file(s) or directories.
Change the password or allow (for the system administrator) to
passwd [name [password]]
change any password.
ps [options] Display a snapshot of the currently running processes.
pwd Display the pathname for the current directory.
rm [options] directory Remove (delete) file(s) and/or directories.
rmdir [options] directory Delete empty directories.
Remotely log in to another Linux machine, over the network.
ssh [options] user@machine
Leave an ssh session by typing exit.
su [options] [user [arguments]] Switch to another user account.
Display the last n lines of a file (the default is
tail [options] [filename]
10).
Store and extract files from a tarfile (.tar) or tarball (.tar.gz or
tar [options] filename
.tgz).
Displays the resources being used on your system. Press q to
top
exit.
touch filename Create an empty file with the specified name.
who [options] Display who is logged on.
Object 2
If this problem happens repeatedly at exactly the same spot, you may have a bad
installation disk. Try the disk in another machine if possible and see if the installation fails in
the same place there. If you purchased this disk with a Linux distribution, contact the
distributions technical support team. If you got the disk with a book, contact the publishers
technical support team. If you burned the disk yourself, try burning a new copy at a slower
speed.
If this problem happens repeatedly at exactly the same spot and you dont have a bad
installation disk, the trouble may be with one of your machines hardware components. If
you can, try trading hardware between machines. If not, you may need to choose a different
machine on which to install Linux or try another distribution.
If the problem seems to happen randomly, your particular Linux distribution may not be
compatible with that particular machine. Again, you can try trading some hardware around,
installing Linux on another machine, or using another distribution.