Connecting to a Unix/Linux system Open up a terminal: zhome:- /linux tutorials
Connecting to a Unix/Linux system Open up a terminal: zhome:- /linux tutorials The host The “prompt” The current directory (“path”)
What exactly is a “shell”? After logging in, Linux/Unix starts another program called the shell The shell interprets commands the user types and manages their execution The shell communicates with the internal part of the operating system called the kernel The most popular shells are: tcsh, csh, korn, and bash The differences are most times subtle For this tutorial, we are using bash Shell commands are CASE SENSITIVE!
Help! Whenever you need help with a command type “man” and the command name
Help! zhome:- /linux tutorials man iWhat manual page do you want? zhome:- /linux tutorials man echo zhome:- /linux tutorials
ECHO ( 1) User Commands ECHO(1) echo — display a line of text SYNOPSIS echo [ OPTION ]... [ STRING ]... DESCRIPTION NOTE: your shell may have its own version of echo which will supercede the version described here. Please refer to your shellas documentation for details about the options it supports. Echo the STRING(s) to standard output. do not output the trailing newline Help!
Help! zhome:•/linux tutorial s man What manual page do you want? zhome:- /linux tutorials man echo hello world zhome:- /linux tutorials hello world zhome:- /linux tutorial$
nix/Linux File System bin NOTE: Unix file names are CASE SENSITIVE! /home/mary/ /home/john/portfolio/ The Path
Command: pwd To find your current path use “pwd” pwd /fs/zhome05/mete/linux tutorial tutorials
Command: cd + To change to a specific directory use “cd” zhome:- $ pwd /fs/zhome05/wiehe zhome: -3 cd /fs/zhome05/wiehe/linux tutorial/ zhome:- /linux tutorial pwd /fs/zhome05/wiehe/linux tutorial zhome:- /linux tutorials
Command: cd - ” is the location of our home directo zhoue:- /linux tutorials pwd /fs/zhome05/wiehe/linux tutorial zhome: /linux tutorials cd - zhome: $ pwd /fs/zhome05/wiehe zhome:•
irectory below d: c “. ” is the location of the current one zhome:- /linux tutorials pwd /fs/zhome05/wiehe/linux tutorial zhome:- /linux tutorials cd .. zhome:- $ pwd /fs/zhome05/wiehe zhome:- $
Command: Is To list the files in the current directory use “Is” zhome:- /linux aa sequence.pl ACTG.pl zho data.dat hello world.pl tutorial$
Command: Is Is has many options - I long list (displays lots of info) - t sort by modification time - S sort by size - h list file sizes in human readable format - r reverse the order “man Is” for more options Options can be combined: “Is - Itr”
Command: Is List files by time in reverse order with long listing 1 wiehe wiehe 92 Aug 30 11:54 ACTG.pl wiehe wiehe 169 Aug 30 12:20 aa sequence.pl 1 wiehe wiehe 42 Aug 30 12:22 hello world.pl wiche wiehe 24 g 30 12 23 tp l wiehe wiehe 21 Aug 30 12:=3 data.dat zhome:- /linux tutorials —rw—rw—r— — -rw-rw—r- - -rw-rw-r- - zhome:- /linux tutorials
General Syntax: * *” can be used as a wildcard in unix/linux tutorials aa sequence.pl ACTG.p1 zhome: /linux tutorials .pl hello world.p1
Command: mkdir *› To create a new directory use “mkdir” zhome:- /linux tutorial aa sequence.pl data.dat hello world.pl ACTG.pl zhome:- /linux tutorials mkdir new directory zhome:- /linux tucorial$ 1s aa sequence.pl data.dat hello world.pl new directory pu ACTG.pl zhome:- /linux tutorial
Command: rmdir To remove and empty directory use “rmdir” zhome:- /linux tutorials aa sequence.pl data.dat new directory ACIG.pl hello world.pl ut zhome:- /linux tutorials rmdir new directory/ zhome:- /linux tutorials aa sequence.pl data.dat hello world.pl ACIG.pl zhome:- /linux tutorial
Displaying a file Various ways to display a file in Unix cat less head tail
Command: cat Dumps an entire file to standard output Good for displaying short, simple files
Command: less Less command is a Linux utility that can be used to read the contents of a text file one page (one screen) at a time. It has faster access because if a file is large, it doesn’t access the complete file, but accesses it page by page. use “/” to search for a string Press to quit
Command: [head (option..) (file..)] The head command, as the name implies, print the top N number of data of the given input. By default, it prints the first 10 lines of the specified files. If more than one file name is provided then data from each file is preceded by its file name.
Command: head Here's an example of using “head”:
Command: [ tail (option..)(filename)] Same as head, but shows the last lines
File mands Copying a file: cp Move or rename a file: mv Remove a file: rm
d: c To copy a file use “cp” zhcme: /linux tutorials aa sequence.pl data.dat lines.txt tpu ACTG.pl hello world.pl zhcme:- /linux tutorials cp data.rat data?.dat zhome:- /linux tutorials aa sequence.pl data2.dat hello world.pl lines.txt ACTS.pl zhome:- /linux data.dat tutorials
Command: mv To move a file to a difierent location use “mv” zhome:- /linux tutorial aa sequence.pl data2.dat ACTG.pl data.dat zhome:- /linux tutorial$ hello world.pl lines.txt new directory zhome:- /linux tutorials aa sequence.pl data2.dat hello world.pl new directory data.dat lines.txt tp xt tutorials data2.dat ./new directory/ tutorials cd new directory/ tutorial/new dliectory$ ACTG.pl zhome:- /linux zhome:- /linux zhome:- /linux data2.dat zhome:- /linux tutorial/new diiectory$
Command: mv + mv can also be used to rename a file zhome: /linux tutorials aa sequence.pl data.dat ACTS pl hello world.pl zhome:- /linux tutorial$ lines.txt new directory pu zhome:- /linux tutorial7 1s aa sequence.pi data.dat ACTG.pi hello world.pl lines.txt zhome:- /linux tutorial$ new directory
Command: rm To remove a file use “rm” zhome:- /linux tutorials cd new directory/ zhome:- /linux tutorial/new directory$ is data2.dat zhome:- /linux tutorial/new directory$ rm data2.dat zhome:- /linux tutorial/new directory¢ zhome:- /linux tutorial/new directorys @
Command: rm To remove a file “recursively”: rm r Used to remove all files and directories Be very careful, deletions are permanent in Unix/Linux
File permissions Each file in Unix/Linux has an associated permission level This allows the user to prevent others from reading/writing/executing their files or directories Use “Is - I filename” to find the permission level of that file
Permission levels “r” means “read only” permission “w” means “write” permission “x” means “execute” permission In case of directory, “x” grants permission to list directory contents
File Permissions zhome: /linux total 28 r rw—r— — -rw-r- - —rw—r— — —rw—r— — -rw-r- - — rv rw—r— — wiehe wiehe wiehe wiehe wiehe wiehe wiehe wiehe wiehe wiehe wiehe wiehe dew rwxr— x wiehe wiehe e:- /linux tutorials User (you) 169 Aug 30 12:20 aa sequence.pl 92 Aug 30 11:54 ACTG.pl 21 Aug 30 12:23 data.dat ug hello world.pl 24 Aug 30 12:23 input.txt 50 Aug 30 13:13 lines.txt 4096 Aug 30 13:19 new directory
File Permissions wiehe wiehe wiehe wiehe wiehe wiehe wiehe wiehe tutorials 169 Aug 30 12:20 aa sequence.pl 92 Aug 30 11:54 ACTG.pl 21 Aug 30 12:23 data.dat ug hello world.pl wiehe wiehe 24 Aug 30 12:23 input.txt —rv— w—r— — wiehe wiehe 50 Aug 30 13:13 lines.txt drwK war— x wiehe wiehe 4096 Aug 30 13:19 new directory
File Permissions zhome: /linux total 28 tutoridl9 ls - l —rv- rw- 1 wiehe wiehe 169 Aug 30 12:20 aa sequence.pl -rv-rw- r wiehe wiehe 92 Aug 30 11:54 ACTG.pl —rv—rw— r wiehe wiehe 21 Aug 30 12:23 data.dat —rv— rw— wiehe wiehe 42 Aug 30 12:22 hello world.pl -rv- rw- wiehe wiehe 24 Aug 30 12:23 input.txt —rv- rw- wiehe wiehe 50 Aug 30 13:13 lines.txt drwKrw wiehe wiehe 4096 Aug 30 13:19 new directory zhome: tutorials “The World”
Command: chmod If you own the file, you can change it's permissions with “chmod” Syntax: chmod [user/group/others/alI]+[permission] [file(s)] Below we grant execute permission to all: —rw—rw—r— — 1 wiehe wiehe chmod world.pl 12 22 hello world.pl hello world.pl zhome:- /linux tutorials —rwxrwxr— x wiehe wiehe 42 Aug 30 12: zhome:- /linux tutorial$
Command: ps To view the processes that you're running: zhome: /linux tutorials ps — u wiehe TIME CMD PID TTY 1194 ? 1196 pts/2 1255 pts/2 1270 pts/2 zhcme:- /linux 00:00:00 sshd 00:00:00 bash 00:00:01 ACTG.pl 00:00:00 ps tutorials
Command: top To view the CPU usage of all processes: top - 13:4o:33 up 50 days, 4:26, 2 users, load avera Tasks: total, sleeping, stoppe Mem: Swap: total, total, ued, used, D S 0.? 0.0 324 29? S 0.0 0.0 RT 0.0 0.0 0.0 0.0 RT . . fOOt 34 19 S . . RT 0.0 0.0 19 0.0 0.0 RT 0.0 0.0 9 root 19 0.0 0.0
Command: kill To terminate a process use “kill” zhome: /linux tutorial - u wiehe PID TTY TIME CMD 1196 pts/2 1255 pts/2 00:00:00 sshd 00:00:00 bash 00:00:01 ACTG.pl 1287 pts/2 00:00:00 ps zhome: /linux tutorial kill - 9 1255 Killed ./ACTG.pl zhome:- /linux tutorial$ wiehe PID TTY TIME CMD 1194 7 00:00:00 ssñd 1196 pts/2 00:00:00 bash 1289 pts/2 00:00:00 ps zhome:- /linux tutorial$
InpuVoutput Redirection (“piping”) Programs can output to other programs Called “piping” “program a | program b” program a's output becomes program b's input “program a > file.txt” program a's output is written to a file called “file.txt” “program a < input.txt” program a gets its input from a file called “input.txt”
few examples of piping zhome: /linux tutorials ./aa sequence.pl less
few examples of zhome:- /linux tutorials aa sequence.pl hello world.pl new directory ACTG.pl xt data.dat lines.txt zhome:- /linux tutorials ./aa sequence.pl > sequence.txt zhome:- /linux tutorials aa sequence.pl hello world.pl ACTG.pl new directory sequence.txt lines.txt data.dat zhome:- /linux tutorials less sequence.txt
Command: we To count the characters, words, and lines in a file use “we” The first column in the output is lines, the second is words, and the last is characters
few examples of zhome:- /linux tutorials ./aa sequence.pl wc 251 zhome: Zlinux tutorial
d: grep To search files in a directory for a specific string use "grep" zhome:- /linux tutorials new_dire:tory sequence.txt data.dat lines.txt zhome:- /linux tutorials grep "hello world" *.pl hello world.pl:print "hello world.\n"; zhome:- /linux tutorials
Command: diff To compare to files for differences use “diff” Try: diff /dev/null hello.txt /dev/null is a special address it is always empty, and anything moved there is deleted