Sie sind auf Seite 1von 24

40 Useful Linux Commands

BY CSARGRNDS · APRIL 13, 2015


If you are a newbie there is a list of commands you must know, to survive on Linux
environments. This commands will help you to move between directories, get system
information, and manage data and users.

40 Useful Linux Commands

Linux Commands for files and directories


handling
1. Command: ls
The command ( ls ) is used list directory content, List information about the files from
the current directory by default

root@nagsis:~# ls

Android-Games Music

Pictures Public

Desktop nagsis.com
Documents nagsis-Sync

Downloads Templates

The command ( ls -l ) use a long listing format

root@nagsis:~# ls -l

total 40588

drwxrwxr-x 2 ravisaive ravisaive 4096 May 8 01:06 Android Games

drwxr-xr-x 2 ravisaive ravisaive 4096 May 15 10:50 Desktop

drwxr-xr-x 2 ravisaive ravisaive 4096 May 16 16:45 Documents

drwxr-xr-x 6 ravisaive ravisaive 4096 May 16 14:34 Downloads

drwxr-xr-x 2 ravisaive ravisaive 4096 Apr 30 20:50 Music

drwxr-xr-x 2 ravisaive ravisaive 4096 May 9 17:54 Pictures

drwxrwxr-x 5 ravisaive ravisaive 4096 May 3 18:44 nagsis.com

drwxr-xr-x 2 ravisaive ravisaive 4096 Apr 30 20:50 Templates

Command ( ls -a ) including hidden files.


root@nagsis:~# ls -a

. .gnupg .dbus .goutputstream-PI5VVW .mission-


control

.adobe deja-dup .grsync .mozilla .themes

.gstreamer-0.10 .mtpaint .thumbnails .gtk-bookmarks .thunderbird

.HotShots .mysql_history .htaccess .apport-ignore.xml .ICEauthority


.profile .bash_history .icons .bash_logout .fbmessenger

.jedit .pulse .bashrc .liferea_1.8 .pulse-cookie


.Xauthority .gconf .local .Xauthority.HGHVWW .cache

.gftp .macromedia .remmina .cinnamon .gimp-2.8

.ssh .xsession-errors .compiz .gnome


teamviewer_linux.deb

2. Command: cd
The Command ( cd ) for change directory, used to change the current working directory
in operating system

root@nagsis:~# cd /home/user/Desktop

3. Command: pwd
The command ( pwd ) print working directory, prints the current working directory,
usefull when you get lost.

root@nagsis:~# pwd

/home/user/Desktop

4. Command: cp
The command ( cp ) stands for copy, it copies a file from one location to another.

root@nagsis:~# cp /home/user/Downloads abc.tar.gz /home/user/Desktop

5. Command: mv
The ( mv ) command moves a file from one location to another location.

root@nagsis:~# mv /home/user/Downloads abc.tar.gz /home/user/Desktop

6. Command: touch
The ( touch ) command stands for update the access and modification times of each
fileto the current time. Creates the file, only if it doesn’t exist. If the file already exists
it will update the timestamp.

root@nagsis:~# touch nagsisfile


7. Command: rm (Use it with caution, Linux don´t have
and undo command.)
The command (rm ) for remove. rm is used to remove files and directories.
Remove files

root@nagsis:~# rm file.name

Remove directories

root@nagsis:~# rm -r directory.name

8. Command: mkdir
The command ( mkdir) for Make directory create a new directory

root@nagsis:~# mkdir nagsis

9. Command: cat
The ( cat ) for concatenation. Print contents of a file on standard output.

root@nagsis:~# cat filr.txt

....

contents of file abcd


...

Linux Commands for system information


10. Command: date
The command (date) print the current date and time.

root@nagsis:~# date

Sat May 02 10:34:29 IST 2015

11. Command: cal


The command “cal” (Calendar), it is used to displays calendar of the present month or
any other month of any year that is advancing or passed.

root@nagsis:~# cal

May 2013

Su Mo Tu We Th Fr Sa

1 2 3 4

5 6 7 8 9 10 11
12 13 14 15 16 17 18

19 20 21 22 23 24 25

26 27 28 29 30 31

12. Command: uname


The Command ( uname ) for Unix Name, print detailed information about the machine
name, Operating System and Kernel.

root@nagsis:~# uname -a

Linux nagsis 3.8.0-19-generic #30-Ubuntu SMP Wed May 1 16:36:13 UTC 2013 i686 i686 i686
GNU/Linux

13. Command: df
Report disk usages of file system. used to display the amount of available disk space
for filesystems

root@nagsis:~# df

Filesystem 1K-blocks Used Available Use% Mounted on

/dev/sda1 47929224 7811908 37675948 18% /


none 4 0 4 0% /sys/fs/cgroup

udev 1005916 4 1005912 1% /dev

tmpfs 202824 816 202008 1% /run

none 5120 0 5120 0% /run/lock

none 1014120 628 1013492 1% /run/shm

none 102400 44 102356 1% /run/user

/dev/sda5 184307 79852 94727 46% /boot

/dev/sda7 95989516 61104 91045676 1% /data

/dev/sda8 91953192 57032 87218528 1% /personal

14. Command: du
Estimate file space usage. Output the summary of disk usages by ever file
hierarchically, i.e., in recursive manner.

root@nagsis:~# du

8 ./Daily Pics/wp-polls/images/default_gradient

8 ./Daily Pics/wp-polls/images/default

32 ./Daily Pics/wp-polls/images
8 ./Daily Pics/wp-polls/tinymce/plugins/polls/langs

8 ./Daily Pics/wp-polls/tinymce/plugins/polls/img

28 ./Daily Pics/wp-polls/tinymce/plugins/polls

32 ./Daily Pics/wp-polls/tinymce/plugins

36 ./Daily Pics/wp-polls/tinymce

580 ./Daily Pics/wp-polls

1456 ./Daily Pics

36 ./Plugins/wordpress-author-box

16180 ./Plugins

12 ./May Articles 2013/Xtreme Download Manager

4632 ./May Articles 2013/XCache

15. Command: uptime


The command (uptime). uptime tells you how long the system has been running.

root@nagsis:~# uptime

08:11:22 up 74 days, 34 min, 2 users, load average: 0.40, 0.36, 0.36


16. Command: man
The command (man) is the system’s manual pager. Man provides online documentation
for all the possible options with a command and its usages.

root@nagsis:~# man command-name

17. Command: whoami


The command ( whoami ) stands for who am i, prints the effective username of the
current user when invoked.

root@nagsis:~# whoami

root

18. Command: who or w


The command ( who or w ), the who command prints information about all users who
are currently logged in.

root@nagsis:~# w

aaron pts/1 2014-01-17 22:42 (:0.0)

smith pts/2 2014-01-18 09:30 (:0.0)


martha pts/0 2013-09-04 22:05 (:0.0)

19. Command: whereis


The command ( whereis ) is used to locate the binary, sources and manual pages of the
command.

root@nagsis:~# whereis ls

ls: /bin/ls /usr/share/man/man1/ls.1.gz

20. Command: history


The command ( history ) for History Event Record, it prints the history of long list of
executed commands in terminal.

root@nagsis:~# history

1 sudo add-apt-repository ppa:tualatrix/ppa

2 sudo apt-get update

3 sudo apt-get install ubuntu-tweak

4 sudo add-apt-repository ppa:diesch/testing

5 sudo apt-get update


6 sudo apt-get install indicator-privacy

7 sudo add-apt-repository ppa:atareao/atareao

8 sudo apt-get update

9 sudo apt-get install my-weather-indicator

10 pwd

11 cd && sudo cp -r unity/6 /usr/share/unity/

12 cd /usr/share/unity/icons/

13 cd /usr/share/unity

Linux Commands for searching


21. Command: locate
The command ( locate) is often the simplest and quickest way to find the locations of
files and directories on Linux and other Unix-like operating systems.

root@nagsis:~# locate file.name

/home/user/tmp/file.name

22. Command: Find


Search for files in the given directory, hierarchically starting at the parent directory and
moving to sub-directories.

root@nagsis:~# find -name *.sh

./Desktop/load.sh

./Desktop/test.sh

./Desktop/shutdown.sh

./Binary/firefox/run-mozilla.sh

./Downloads/kdewebdev-3.5.8/quanta/scripts/externalpreview.sh

./Downloads/kdewebdev-3.5.8/admin/doxygen.sh

./Downloads/kdewebdev-3.5.8/admin/cvs.sh

./Downloads/kdewebdev-3.5.8/admin/ltmain.sh

./Downloads/wheezy-nv-install.sh

Note: For no case sensitive. You can use the `-iname‘ option to find something.

root@nagsis:~# find -iname *.SH ( find -iname *.Sh / find -iname *.sH)

./Desktop/load.sh
./Desktop/test.sh

./Desktop/shutdown.sh

./Binary/firefox/run-mozilla.sh

./Downloads/kdewebdev-3.5.8/quanta/scripts/externalpreview.sh

./Downloads/kdewebdev-3.5.8/admin/doxygen.sh

./Downloads/kdewebdev-3.5.8/admin/cvs.sh

./Downloads/kdewebdev-3.5.8/admin/ltmain.sh

./Downloads/wheezy-nv-install.sh

root@nagsis:~# find -name *.tar.gz

/var/www/modules/update/tests/aaa_update_test.tar.gz

./var/cache/flashplugin-nonfree/install_flash_player_11_linux.i386.tar.gz

./home/server/Downloads/drupal-7.22.tar.gz

./home/server/Downloads/smtp-7.x-1.0.tar.gz

./home/server/Downloads/noreqnewpass-7.x-1.2.tar.gz

./usr/share/gettext/archive.git.tar.gz

./usr/share/doc/apg/php.tar.gz
./usr/share/doc/festival/examples/speech_pm_1.0.tar.gz

./usr/share/doc/argyll/examples/spyder2.tar.gz

./usr/share/usb_modeswitch/configPack.tar.gz

23. Command: grep


The command ( grep ) searches the given file for lines containing a match to the given
strings or words.

root@nagsis:~# grep nagsis /etc/passwd

nagsis:x:1000:1000:Nagsis,,,:/home/nagsis:/bin/bash

Also read: Using Grep To Search For Text Patterns

Linux Commands for file permissions


24. Command: chmod
The command ( chmod ) for (change file mode bits). chmod changes the file mode
(permission) of each given file, folder, script, etc.. .

root@nagsis:~# chmod 777 abc.sh

25. Command: chown


The command ( chown ) stands for change file owner and group.

root@nagsis:~# chown root.root file

drwxr-xr-x 3 root root 4096 May 10 11:14 file

drwxr-xr-x 2 server server 4096 May 13 09:42 Desktop

Also read: Managing Linux Permissions

Linux Commands for process management


26. Command: ps
The command ( ps ) for process gives the status of running processes with a
unique Id called PID.

root@nagsis:~# ps

PID TTY TIME CMD

4170 pts/1 00:00:00 bash

9628 pts/1 00:00:00 ps

To list status of all the processes along with process id and PID, use option ‘-A‘.
root@nagsis:~# ps -A

PID TTY TIME CMD

1 ? 00:00:01 init

2 ? 00:00:00 kthreadd

3 ? 00:00:01 ksoftirqd/0

5 ? 00:00:00 kworker/0:0H

7 ? 00:00:00 kworker/u:0H

8 ? 00:00:00 migration/0

9 ? 00:00:00 rcu_bh

....

This command is very useful when you want to know which processes are running or
may need PID sometimes, for process to be killed. You can use it with ‘grep‘ command
to find customised output. For example,

root@n:~# ps -A | grep -i ssh

1500 ? 00:09:58 sshd


4317 ? 00:00:00 sshd

27. Command: kill


The command ( kill ). The kill command will kill a process using the kill signal and
PID given by the user. The kill command works together with the ps command

root@nagsis:~# ps -A | grep -i postfix

1285 ? 00:00:00 postfix

Find process postfix, note its pid and kill it. For example, in my case postfix pid is
‘1285‘.

root@nagsis:~# kill 1285 (to kill the process postfix)

28. Command: service


The command ( service ) controls the Starting, Stopping or Restarting of a service.

root@nagsis:~# service postfix start

root@nagsis:~# service postfix stop

root@nagsis:~# service postfix restart


Linux Commands for compress files
29. Command: tar
The command ( tar ) is a Tape Archive is useful in creation of archive, in a number of
file format and their extraction.

root@nagsis:~# tar -zxvf file.tar.gz (Remember 'z' for .tar.gz)

root@nagsis:~# tar -jxvf file.tar.bz2 (Remember 'j' for .tar.bz2)

root@nagsis:~# tar -cvf file.tar.gz(.bz2) /path/to/folder/file

Linux Commands for Network


30. Command: ping
The command ( ping ), is the best way to test connectivity between two nodes. Whether
it is Local Area Network (LAN) or Wide Area Network (WAN). Ping use ICMP
(Internet Control Message Protocol)

# ping www.teknixx.com

PING teknixx.com (23.229.227.194) 56(84) bytes of data.

64 bytes from 23.229.227.194: icmp_seq=1 ttl=47 time=284 ms

64 bytes from 23.229.227.194: icmp_seq=2 ttl=47 time=287 ms


64 bytes from 23.229.227.194: icmp_seq=3 ttl=47 time=285 ms

31. Command: traceroute


The command ( traceroute ) traceroute – print the route packets take to network host.

# traceroute 23.229.227.194

traceroute to 23.229.227.194 (23.229.227.194), 30 hops max, 60 byte packets

1 192.168.50.1 (192.168.50.1) 0.217 ms 0.624 ms 0.133 ms

2 227.18.106.27.mysipl.com (27.106.18.227) 2.343 ms 1.910 ms 1.799 ms

3 221-231-119-111.mysipl.com (111.119.231.221) 4.334 ms 4.001 ms 5.619 ms

4 10.0.0.5 (10.0.0.5) 5.386 ms 6.490 ms 6.224 ms

5 gi0-0-0.dgw1.bom2.pacific.net.in (203.123.129.25) 7.798 ms 7.614 ms 7.378 ms

6 115.113.165.49.static-mumbai.vsnl.net.in (115.113.165.49) 10.852 ms 5.389 ms 4.322 ms

7 ix-0-100.tcore1.MLV-Mumbai.as6453.net (180.87.38.5) 5.836 ms 5.590 ms 5.503 ms

8 if-9-5.tcore1.WYN-Marseille.as6453.net (80.231.217.17) 216.909 ms 198.864 ms 201.737


ms

32. Command: netstat


The command ( netstat ) is a useful tool for checking your network configuration and
activity.

# netstat -r

Kernel IP routing table

Destination Gateway Genmask Flags MSS Window irtt Iface

192.168.50.0 * 255.255.255.0 U 0 0 0 eth0

link-local * 255.255.0.0 U 0 0 0 eth0

default 192.168.50.1 0.0.0.0 UG 0 0 0 eth0

33. Command: hostname


The command ( hostname ) shows or sets the system hostname.

# hostname

teknixx.com

34. Command: dig


The command ( dig ) for domain information groper, you can query DNS name servers
for your DNS lookup related tasks.
# dig www.teknixx.com; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.10.rc1.el6 <<>> www.teknixx.com

;; global options: +cmd

;; Got answer:

;; ->>HEADER<

35. Command: nslookup


The command ( nslookup ) also use to find out DNS related query. The following
examples shows A Record (IP Address) of teknixx.com.

# nslookup www.teknixx.com

Server: 11.8.88.1

Address: 11.8.88.1#53

Non-authoritative answer:

www.teknixx.com canonical name = teknixx.com.

Name: teknixx.com

Address: 23.229.227.194

36. Command: arp


The command ( arp ) for Resolution Protocol is useful to view / add the contents of the
kernel’s ARP tables. To see default table use the command as.

# arp -e

Address HWtype HWaddress Flags Mask Iface

192.168.50.1 ether 00:50:56:c0:00:08 C eth0

37. Command: telnet


The command ( telnet ) Connects destination host via telnet protocol, if telnet
connection establish on any port means connectivity between two hosts is working fine.

# telnet teknixx.com 80

Linux Commands for users administration


38. Command: adduser or useradd
The command ( adduser ) create a new user. The ‘username’ is a user login name, that
is used by user to login into the system.

[root@teknixx~]# useradd smith

39. Command: passw


The command ( passw ) change or set user password.

[root@teknixx~]# passw smith

40. Command: su
The command ( su ) become root .

[root@teknixx~]# su smith

Das könnte Ihnen auch gefallen