30
Basic linux commands By, tha.suresh [email protected] Kanchi Lug Member

Linux Commands - 3

Embed Size (px)

Citation preview

Page 1: Linux Commands - 3

Basic linux commands

By,

tha.suresh

[email protected]

Kanchi Lug Member

Page 2: Linux Commands - 3

LIST...

● ls [options] [file|directory]●

-l

will output the files and directories in long list format.

-s, --size

print the size of each file, in blocks

-S sort by file size

-a, --all

do not ignore entries starting with .

Page 3: Linux Commands - 3

Examble for “ls”● arul@arul-desktop:~$ ls -l● total 9692● drwxr-xr-x 2 arul arul 4096 2009-10-

17 22:12 Desktop● drwxr-xr-x 2 arul arul 4096 2009-10-

17 22:35 Documents● drwxr-xr-x 2 arul arul 4096 2009-10-

17 17:58 event

Page 4: Linux Commands - 3

● ls list all files

● ls -l list all files with details

● ls *.gif list gif files

● ls *.gif -l list gif files with details

● ls | wc -l count all files

● ls *.gif | ws -l count gif files

● (wc = word count)

Page 5: Linux Commands - 3

COPY...

● cp [OPTION]... SOURCE DEST● cp

is the Linux copy command, this shell command is used to copy files|directories from one location on the filesystem to another.

Page 6: Linux Commands - 3

options.

● -f, --force● if an existing destination file cannot be

opened, remove it and try again● -i, --interactive● prompt before overwrite● -R, -r, --recursive● copy directories recursively

Page 7: Linux Commands - 3

● cp *.txt text● It will copy all files ending in .txt into the text

directory.●

To copy a file to your home directory:

cp /usr/local/doc/ue.txt $HOME

This copies the file ue.txt to your home directory

Page 8: Linux Commands - 3

● To copy a file to the parent directory:● cp mail.txt ..● This copies the file mail.txt to the directory

immediately above the current working directory.

Page 9: Linux Commands - 3

-f, --force if an existing destination file cannot be opened, remove it and try again

• -i, --interactive prompt before overwrite

• -l, --link link files instead of copying.

• -p same as --preserve=mode,ownership,timestamps

• -R, -r, --recursive copy directories recursively

• -s, --symbolic-link make symbolic links instead of copying

• -u, --update copy only when the SOURCE file is newer than the destination file or when the destination file is missing

• -v, --verbose explain what is being done

Page 10: Linux Commands - 3

MOVE....

● mv [OPTION]... [-T] SOURCE DEST

● the Linux terminal command to move files|directories. Like the cp command, but deletes the original source.

Page 11: Linux Commands - 3

REMOVE...

● rm -f [file]● option is if you are wanting to force a file to

be removed● rm -r files● (recursive remove) Remove files,

directories, and their subdirectories

Page 12: Linux Commands - 3

TOUCH....

● arul@arul-desktop:~/Desktop$ ls● Home.desktop ShellIntro.pdf su

trash.desktop● arul@arul-desktop:~/Desktop$ touch new

new1 new2● arul@arul-desktop:~/Desktop$ ls● abc Home.desktop new new1 new2

ShellIntro.pdf su trash.desktop zxc

Page 13: Linux Commands - 3

CAT...

● The Linux cat command is the Unix command to list a file’s contents onto your screen, or pass via pipeline to use with other Linux commands. The cat command comes from the word concatenate.

Page 14: Linux Commands - 3

● arul@arul-desktop:~/Desktop$ cat new

● arul@arul-desktop:~/Desktop$ vim new● arul@arul-desktop:~/Desktop$ cat new● sure● arul● shrini

Page 15: Linux Commands - 3

mkdir

● The Linux command mkdir is used to make directories in Linux.

● mkdir - make directories●

Page 16: Linux Commands - 3

Example

● arul@arul-desktop:~/Desktop$ ls● abc Home.desktop new new1 new2

ShellIntro.pdf su trash.desktop zxc● arul@arul-desktop:~/Desktop$ mkdir comm● arul@arul-desktop:~/Desktop$ ls● abc comm Home.desktop new new1

new2 ShellIntro.pdf su trash.desktop zxc

Page 17: Linux Commands - 3

grep

grep [OPTIONS] PATTERN [FILE...]● The Linux grep command is used to extract

lines of data from files●

arul@arul-desktop:~/Desktop$ grep sure newsurearul@arul-desktop:~/Desktop$ grep s newsureshrini

Page 18: Linux Commands - 3

WORD COUNT...

● wc counts the characters,lines,words in a file.● Options:● -c output char., count● -l output lines count● -w output words count

Page 19: Linux Commands - 3

Example

● wc -w linux.txt● 34● Display the word count for linux.txt● Defult: -clw

Page 20: Linux Commands - 3

WHO AM I

● Find which user is loged

shrinivasan@shrinivasan-laptop:~$ whoami

shrinivasan

Page 21: Linux Commands - 3

DATE

● For display the today's date.● Date prints the systems time and date.● shrinivasan@shrinivasan-laptop:~$ date● Sun Oct 18 13:46:29 IST 2009

Page 22: Linux Commands - 3

CALENDAR..● Cal prints an ASCII calendar of the current

month.● Cal display the calendar● shrinivasan@shrinivasan-laptop:~$ cal

October 2009

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

Page 23: Linux Commands - 3

EXAMPLE

● shrinivasan@shrinivasan-laptop:~$ cal 12 1988● December 1988● 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

Page 24: Linux Commands - 3

At command

● shrinivasan@shrinivasan-laptop:~$ at 13:57● warning: commands will be executed using /bin/

sh● at> echo "hello" > hai● at> <EOT>

shrinivasan@shrinivasan-laptop:~$ touch hai● shrinivasan@shrinivasan-laptop:~$ cat hai

hello

Page 25: Linux Commands - 3

Ps

● ps - report a snapshot of the current processes● To see every process on the system using BSD

syntax:● ps -ax● ps -axu

Page 26: Linux Commands - 3

EXAMPLE

●Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html

●USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND

●root 1 0.0 0.0 3084 1888 ? Ss 12:21 0:01 /sbin/init

●root 2 0.0 0.0 0 0 ? S< 12:21 0:00 [kthreadd]

●root 3 0.0 0.0 0 0 ? S< 12:21 0:00 [migration/0]

●root 4 0.0 0.0 0 0 ? S< 12:21 0:00 [ksoftirqd/0]

●root 5 0.0 0.0 0 0 ? S< 12:21 0:00 [watchdog/0]

●root 6 0.0 0.0 0 0 ? S< 12:21 0:00 [events/0]

●root 7 0.0 0.0 0 0 ? S< 12:21 0:00 [khelper]

●root 8 0.0 0.0 0 0 ? S< 12:21 0:00 [kstop/0]

●root 9 0.0 0.0 0 0 ? S< 12:21 0:00 [kintegrityd/0]

●root 10 0.0 0.0 0 0 ? S< 12:21 0:00 [kblockd/0]

●1000 6967 0.0 0.1 8332 3124 ? S 12:55 0:00 /usr/lib/gvfs/gvfs-gphoto2-volume-monitor

●1000 7253 1.7 2.0 125404 42836 ? S 13:03 1:02 /usr/bin/okular /home/shrini/Desktop/nice_linux_guide.pdf -icon okular -

●1000 7343 4.2 5.8 246512 120996 ? Sl 13:04 2:30 /usr/lib/openoffice/program/soffice.bin -impress /home/shrini/Desktop/li

●postfix 10471 0.0 0.0 5792 1684 ? S 13:59 0:00 pickup -l -t fifo -u -c

●1000 10698 0.0 0.0 2768 1032 pts/1 R+ 14:03 0:00 ps -axu

● shrinivasan@shrinivasan-laptop:~$ ps -axu

Page 27: Linux Commands - 3

Kill the opretion

●Kill -9 6967

●Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html

●USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND

●root 1 0.0 0.0 3084 1888 ? Ss 12:21 0:01 /sbin/init

●root 2 0.0 0.0 0 0 ? S< 12:21 0:00 [kthreadd]

●root 3 0.0 0.0 0 0 ? S< 12:21 0:00 [migration/0]

●root 4 0.0 0.0 0 0 ? S< 12:21 0:00 [ksoftirqd/0]

●root 5 0.0 0.0 0 0 ? S< 12:21 0:00 [watchdog/0]

●root 6 0.0 0.0 0 0 ? S< 12:21 0:00 [events/0]

●root 7 0.0 0.0 0 0 ? S< 12:21 0:00 [khelper]

●root 8 0.0 0.0 0 0 ? S< 12:21 0:00 [kstop/0]

●root 9 0.0 0.0 0 0 ? S< 12:21 0:00 [kintegrityd/0]

●root 10 0.0 0.0 0 0 ? S< 12:21 0:00 [kblockd/0]

●1000 7253 1.7 2.0 125404 42836 ? S 13:03 1:02 /usr/bin/okular /home/shrini/Desktop/nice_linux_guide.pdf -icon okular -

●1000 7343 4.2 5.8 246512 120996 ? Sl 13:04 2:30 /usr/lib/openoffice/program/soffice.bin -impress /home/shrini/Desktop/li

●postfix 10471 0.0 0.0 5792 1684 ? S 13:59 0:00 pickup -l -t fifo -u -c

●1000 10698 0.0 0.0 2768 1032 pts/1 R+ 14:03 0:00 ps -axu

Page 28: Linux Commands - 3

TOP..

●shrinivasan@shrinivasan-laptop:~$ top

●top - 14:15:16 up 1:53, 1 user, load average: 0.74, 0.88, 0.75

●Tasks: 152 total, 3 running, 149 sleeping, 0 stopped, 0 zombie

●Cpu(s): 17.2%us, 3.3%sy, 0.0%ni, 79.5%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

●Mem: 2061340k total, 1424900k used, 636440k free, 63056k buffers

●Swap: 1951856k total, 0k used, 1951856k free, 564504k cached

● PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND

● 3963 shriniva 20 0 349m 135m 28m S 7.9 6.7 9:15.43 firefox-bin

● 3433 root 20 0 356m 268m 6048 R 5.0 13.3 7:27.77 Xorg

● 3916 shriniva 20 0 343m 53m 31m R 3.3 2.7 3:27.88 plasma

● 3966 shriniva 20 0 134m 28m 17m S 2.0 1.4 0:23.26 konsole

● 3944 shriniva 20 0 94168 26m 20m S 0.7 1.3 0:38.21 ktorrent

●11311 shriniva 20 0 2448 1212 912 R 0.7 0.1 0:00.12 top

● 2657 mysql 20 0 124m 16m 4948 S 0.3 0.8 0:05.77 mysqld

● 4039 shriniva 20 0 678m 52m 14m S 0.3 2.6 0:26.06 java

● 1 root 20 0 3084 1888 564 S 0.0 0.1 0:01.41 init

● 2 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 kthreadd

● 3 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/0

● 4 root 15 -5 0 0 0 S 0.0 0.0 0:00.20 ksoftirqd/0

● 5 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/0

● 6 root 15 -5 0 0 0 S 0.0 0.0 0:00.05 events/0

Page 29: Linux Commands - 3

crontab

● # m h dom mon dow command● 53 14 * 10 * echo"hai" >

/root/shrini/home/hai

● shrinivasan@shrinivasan-laptop:~$ cat hai● hello

Page 30: Linux Commands - 3

THANK YOU