Useful Commands For The Linux Command Line

This short guide shows some important commands for your daily work on the Linux command line.

arch

Outputs the processor architecture.

$ arch

i686

cat

Outputs the contents of a file.

$ cat lorem.txt

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

cd

Change the working directory.

$ cd /bin

cksum

Print CRC checksum and byte counts of each file.

$ cksum lorem.txt moo.txt

3570240675 453 lorem.txt
4294967295 0 moo.txt

cp

Copies a file.

$ cp lorem.txt copy_of_lorem.txt

date

Outputs the current date and time.

$ date

Ads_kid=0;Ads_bid=0;Ads_xl=0;Ads_yl=0;Ads_xp=”;Ads_yp=”;Ads_xp1=”;Ads_yp1=”;Ads_opt=0;Ads_wrd='[KeyWord]’;Ads_par=”;Ads_cnturl=”; function Ads_PopUp() {}

Sat Mar  3 12:07:09 GMT 2007

df

Reports the amount of disk space used and available on filesystems.

$ df

Filesystem           1K-blocks      Used Available Use% Mounted on<br>
/dev/simfs            39845888    218048  39627840   1% /

dir

List directory contents.

$ dir

copy_of_lorem.txt  lorem.txt  moo.txt  www

du

Estimate file space usage.

$ du -h /bin

7.8M    /bin

echo

Display a line of text.

$ echo foobar

foobar

fgrep

Print lines matching a pattern in a file.

$ fgrep “irure dolor” lorem.txt

commodo consequat. Duis aute irure dolor in reprehenderit in voluptate

groups

Outputs the user groups of which your account belongs to.

$ groups

games users

hostname

Outputs the machines hostname on the network.

$ hostname

anapnea.net

id

Outputs user id, group id, and groups of your account.

$ id

uid=1478(smallfoot) gid=100(users) groups=35(games),100(users)

ls

List directory contents.

$ ls

copy_of_lorem.txt  lorem.txt  moo.txt  www

man

Opens the manual page for a software or function.

$ man bash

md5sum

Outputs the MD5 hash sum of a file.

$ md5sum lorem.txt

56da9e37259af34345895883e6fd1a27  lorem.txt

mkdir

Makes a directory.

$ mkdir foobar

mv

Moves a file.

$ mv lorem.txt ipsum.txt

ping

Pings a host.

$ ping -c 2 127.0.0.1

PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.048 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.052 ms

— 127.0.0.1 ping statistics —
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.048/0.050/0.052/0.002 ms

ps

Outputs running processes.

$ ps

  PID TTY          TIME CMD
21542 pts/12   00:00:00 bash
27706 pts/12   00:00:00 ps

pstree

Display a tree of processes.

$ pstree

init-+-2*[BitchX]
|-3*[bash—sleep]
|-fetchmail
|-screen-+-bash—irssi
|        `-bash—ctorrent
|-screen-+-bash—lisp.run
|        |-bash—vi
|        |-2*[bash]
|        `-bash—lynx
|-2*[screen—bash—irssi]
|-screen—irssi
|-screen—bash
|-screen-+-bash
|        `-irssi
|-skjerm—irssi
|-sshd-+-5*[sshd—sshd—bash—irssi]
|      |-8*[sshd—sshd—bash]
|      |-sshd—sshd—bash—screen
|      |-sshd—sshd
|      `-sshd—sshd—bash—pstree
`-syslog-ng

pwd

Outputs the name of current working directory.

$ pwd

/home/smallfoot

sha1sum

Outputs the SHA1 hash sum of a file.

$ sha1sum lorem.txt

c942ddebd142ec8bacac9213d48096e74bab4957  lorem.txt

stat

Outputs file status.

$ stat lorem.txt

  File: `lorem.txt’
Size: 453             Blocks: 8          IO Block: 4096   regular file
Device: 77h/119d        Inode: 27312217    Links: 1
Access: (0644/-rw-r–r–)  Uid: ( 1478/smallfoot)   Gid: (  100/   users)
Access: 2007-03-03 12:24:39.000000000 +0000
Modify: 2007-03-03 12:24:39.000000000 +0000
Change: 2007-03-03 12:24:39.000000000 +0000

rm

Removes a file or directory.

$ rm lorem.txt

rmdir

Removes a directory.

$ rmdir foobar

touch

Change a file’s access and modification timestamps. If file does not exist, create it.

$ touch lorem.txt

tty

Outputs the name of the current terminal.

$ tty

/dev/pts/16

uname

Outputs operating system, hostname, kernel version, date and timp, and processor.

$ uname -a

Linux anapnea.net 2.6.9 #1 SMP Wed Jul 19 16:24:18 MSD 2006 i686 Intel(R) Xeon(TM) CPU 2.80GHz GenuineIntel GNU/Linux

uptime

Outputs the system uptime.

$ uptime

 14:50:26 up 7 days, 17:52, 18 users,  load average: 0.08, 0.02, 0.01

users

Print the user names of users currently logged in to the current host.

$ users

alice bob charlie eve

vdir

List directory contents.

$ vdir

total 8
-rw-r–r– 1 smallfoot users 453 Mar  3 12:32 copy_of_lorem.txt
-rw-r–r– 1 smallfoot users 453 Mar  3 12:24 lorem.txt
-rw-r–r– 1 smallfoot users   0 Mar  3 12:32 moo.txt
lrwxr-xr-x 1 root      root   18 Feb 27 19:33 www -> /var/www/smallfoot

w

Show who is logged on and what they are doing.

$ w

 12:14:30 up 5 days, 15:16, 19 users,  load average: 0.00, 0.00, 0.00
USER     TTY        LOGIN@   IDLE   JCPU   PCPU WHAT
charlie  pts/0     Fri21    3:26m  2.52s  2.52s irssi
alice    pts/2     Wed17   30:21m  0.00s  0.00s -bash
emma     pts/4     11:37   36:57   0.00s  0.00s -bash
frank    pts/5     11:48   11:03   0.00s  0.00s -bash
smallfoo pts/12    12:01    0.00s  0.04s  0.01s w

wc

Counts lines in a file.

$ wc -l lorem.txt

7 lorem.txt

who

Outputs who is currently logged into the system.

$ who

charlie  pts/0        Mar  2 21:37 (xtreme-11-65.acme.com)
alice    pts/2        Feb 28 17:48 (147.21.16.3)
emma     pts/4        Mar  3 11:37 (32.84-48-181.uac.com)
frank    pts/5        Mar  3 11:48 (port-212-202-233-2.foobar.org)
smallfoot pts/12       Mar  3 12:01 (c-12776f4.cust.example.net)

whoami

Outputs your username / the name of your account.

$ whoami

smallfoot

 

Read more at  Howtoforge.com

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s