Tuesday, July 29, 2008

Useful commands for the Linux Users

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


1. arch: Outputs the processor architecture.

$ arch

i386


2. cat: Outputs the contents of a file.

$ cat show.txt

Display the content of files.............


3. cd: Change the working directory.

$ cd /bin


4. chgrp: Change group ownership of files.

$ chgrp games moo.txt


5. chmod: Change access permissions of files.

$ chmod +x helloworld



6. chown: Change file owner and group.
#ls -lrt ranjan.txt
-rw-r--r-- 1 arvind arvind 9704 2007-11-11 17:46 ranjan.txt

# chown ranjan ranjan.txt
-rw-r--r-- 1 ranjan ranjan 9704 2007-11-11 17:46 ranjan.txt
(Now owner of the file is ranjan)


7. cp: Copies a file.

$ cp source.txt /bin/new.txt (new file will contain same as of source.txt inside /bin directory)



8. date: Outputs the current date and time.

$ date
Sat Mar 3 12:07:09 GMT 20079.


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

$ df

Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 10594480 2762396 7293908 28% /
varrun 252728 240 252488 1% /var/run
varlock 252728 0 252728 0% /var/lock
procbususb 252728 112 252616 1% /proc/bus/usb
udev 252728 112 252616 1% /dev
devshm 252728 0 252728 0% /dev/shm
lrm 252728 33788 218940 14% /lib/modules/2.6.20-16-generic/volatile
/dev/sda2 210003 39548 159612 20% /boot
/dev/sda8 6744132 3379620 3021928 53% /home
/dev/sda1 10482380 2035140 8447240 20% /media/sda1
/dev/sda7 4806904 140844 4421876 4% /tmp
/dev/sda6 4806904 538408 4024312 12% /var

10. dir: List directory contents.

$ dir

ranjan.txt text.txt ddlg.avi


11. du: Estimate file space usage.

$ du -h /bin

7.8M /bin


12. echo: Display a line of text.

$ echo foobar

foobar


13. exit: Cause the shell to exit.

$ exit


14. fgrep: Print lines matching a pattern in a file.

$ fgrep "irure dolor" lorem.txt



15. grep: Print lines matching a pattern.


$ grep -i apple fruitlist.txt

apple
groups


16. find: Search for files in a directory hierarchy.

$ find hello*

hello_world
hello_world.c




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

$ id

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

18. kill: End a process.

$ kill -9 18298


19. killall: Kill processes by name.

$ killall irssi

irssi(18298): Operation not permitted
irssi(13372): Operation not permitted
irssi(22048): Operation not permitted
irssi: no process killed


20. last: Show listing of last logged in users.

$ last -n 3

alice pts/6 192.0.34.166 Fri May 18 16:17 still logged in
bob pts/2 64.233.183.103 Fri May 18 16:17 still logged in
clare pts/6 72.5.124.61 Fri May 18 15:54 - 15:55 (00:01)


21. ldd: Print shared library dependencies.

$ ldd /bin/bash

libncurses.so.5 => /lib/libncurses.so.5 (0x40023000)
libdl.so.2 => /lib/libdl.so.2 (0x40065000)
libc.so.6 => /lib/libc.so.6 (0x40069000)
/lib/ld-linux.so.2 (0x40000000)


22. ln: Make links between files.

$ ln -s data.txt symlink.txt


23. logname: Print user's login name.

$ logname

ranjan


24. ls: List directory contents.

$ ls

copy_of_lorem.txt lorem.txt moo.txt www


25. man: Opens the manual page for a software or function.

$ man bash

26. mkdir: Makes a directory.

$ mkdir foobar

27. mv: Moves a file.

$ mv lorem.txt ipsum.txt


28.od: Dump files in octal and other formats.

$ od -t x /bin/sh

2376640 00098020 000054d4 00000000 00000000
2376660 00000020 00000000 000000c7 00000008
2376700 00000003 080e6500 0009d4f4 00004ae8
...


29.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


30.ps: Outputs running processes.

$ ps

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


31.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



32. pwd: Outputs the name of current working directory.

$ pwd

/home/smallfoot


33. rm: Removes a file or directory.

$ rm lorem.txt


34. rmdir: Removes a directory.

$ rmdir foobar


35. size: List section sizes and total size.

$ size /bin/bash

text data bss dec hex filename
621233 22712 19176 663121 a1e51 /bin/bash


36. 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


37. tail: Output the last part of files.

$ tail -2 lorem.txt

occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum.


38. talk: Talk to another user.

$ talk bob Lookout for the dopefish!


39. touch: Change a file's access and modification timestamps. If file does not exist, create it.

$ touch lorem.txt


40. tty: Outputs the name of the current terminal.

$ tty

/dev/pts/16


41. 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

42. uptime: Outputs the system uptime.

$ uptime

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


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

$ users

alice bob charlie eve


44. 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



45. 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


46. wall: Send a message to everybody's terminal.

$ wall next week we change the server for a new one


47. whatis: Search the whatis database for complete words.

$ whatis bash

bash (1) - GNU Bourne-Again SHell
bash [builtins] (1) - bash built-in commands, see bash(1)


48. 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)


50. whereis: Locate the binary, source, and manual page files for a command.

$ whereis bash

bash: /bin/bash /etc/bash /usr/share/man/man1/bash.1.gz


51. whoami: Outputs your username / the name of your account.

$ whoami

ranjan

No comments: