150 likes | 351 Views
Shell . Current shell. $ ps PID TTY TIME CMD 5355 pts /0 00:00:00 bash 5381 pts /0 00:00:00 ps $ csh $ ps PID TTY TIME CMD 5355 pts /0 00:00:00 bash 5389 pts /0 00:00:00 csh 5409 pts /0 00:00:00 ps. Command compatibility. $ type date
E N D
Current shell $ ps PID TTY TIME CMD 5355 pts/0 00:00:00 bash 5381 pts/0 00:00:00 ps $ csh $ ps PID TTY TIME CMD 5355 pts/0 00:00:00 bash 5389 pts/0 00:00:00 csh 5409 pts/0 00:00:00 ps
Command compatibility $ type date date is /bin/date $ type cd cd is a shell builtin
File system commands • Working directory $cd / $cd /home/class • Absolute and relative paths $cd /home absolute $cd .. relative • How to determine current directory? $pwd • Listing the contents of directory $ ls
Create directory $ mkdir grapple $ mkdir –p vehicles/cars/4wds hierarchy of directories • Remove directory $ rmdir grapple (rmdir removes only empty directories) $ rm –r vehicles (removes all subdirectories and files)
Creating Files $ touch file.txt $ cat>file.txt • Remove files $ rm file.txt • Moving files $ mv file.txt file1.txt $ mv file1.txt /etc/myfiles
Process management commands • Listing processes $ ps PID TTY TIME CMD 5355 pts/0 00:00:00 bash 5381 pts/0 00:00:00 ps $ ps -A PID TTY TIME CMD 1 ? 00:00:04 init 2 ? 00:00:00 keventd 3 ? 00:00:03 kapmd 4 ? 00:00:00 ksoftirqd_CPU0 5 ? 00:00:03 kswapd
Terminating a process $ kill -s SIGTERM 5356 SIGTERM – allows the process to close the files before exiting SIGKILL – forces the process to terminate immidiately.
Switching Identities $ id uid=500(brucewayne) gid=513(users) groups=513(users) $ su Password: bash# id uid=0(root) gid=0(root) groups=0(root), 1(bin), 2(daemon) bash# exit $ id uid=500(brucewayne) gid=513(users) groups=513(users) $ su batman Password: $ id uid=800(batman) gid=513(users) groups=513(users)
Shut down $ shutdown $shutdown –t n • Reboot $reboot • Disk Usage $df partition by partition summary
Mounting Disks # ls /mnt/cdrom At this stage, no files are listed since there is no device associated with the /mnt/cdrom mount point. # mount /mnt/cdrom # ls /mnt/cdrom RedHat Autorun README # umount /mnt/cdrom
Listing users $who • History command $history 1 ls -al 2 date 3 pwd 4 who 5 touch cellar/maze/labyrinth/passage/foo.txt • $ !2 • date Tue Jan 14 23:03:43 2003Sd
To execute last command $!! • Command completion $da<Tab> If conflict, it beeps and waits for user input
File Globbing • The asterisk (*) represents zero or more matches of any characters. • The question mark (?) represents a match of exactly one character. • The square brackets ([ ]) match any one of the characters between them. The characters to match may also be specified as a hyphen-separated range of characters to match against • ! Means not