Basic file operations
cd directory change into directory
cd /dir1/dir2 change into directory (absolute path)
cd .. move up one directory
pwd print current directory
ls list files in current directory
ls –a list hidden files (eg .login)
ls –l long list (details) of current directory
ls –lrt list files with most recently modified at bottom
cat file show contents of file
more file show contents of file to screen:
<return> to advance one line
<space> to advance one page
head file show first ten lines of file
tail file show last ten lines of file
touch file create file (empty)
mkdir dir create a directory called dir
cp file1 file2 make a copy of file1 called file2
cp file directory copy file into directory
cp file /dir/dir2 copy file into directory (absolute path)
cp /dir/file . copy file from /dir to current directory (.)
cp –r dir1 dir2 copy directory dir1 and its contents to dir2
mv file1 file2 rename file1 as file2
mv file dir move file to directory dir
mv file /dir1/dir2 move file to directory dir2 (absolute path)
mv /dir/file . move file from ./dir to current directory (.)
mv dir1 dir2 rename dir1 as dir2
rm file removes file
rm –r dir removes dir and all contents
\rm –r dir removes dir and all contents without prompts (careful!)
Metacharacters
* wildcard for any amount of characters
(eg *.exe – any file ending in .exe)
? wildcard for single character
[ ] enclose wildcard ranges
(eg [a-z], [1-9])
Special characters
$var The value of variable var
“ “ preserve whitespace and ignore metacharacters
‘ ‘ as above but also preserve special characters
` ` enclose system commands
(eg echo Directory is `pwd`)
; Enables multiple commands on one line
( ) > Encloses multiple commands with common output
\ Used before a special or metacharacter to ignore its meaning (similar to single quotes)
File and Process Redirection
cmd > file redirect output to a file
(eg ls > list produces a file called list, containing filenames from current directory)
cmd >> file append output to an existing file
(eg cat file2 >> file1 adds the text of file2
to the end of file1)
cmd1 | cmd2 pass output from cmd1 to cmd2
(eg ls –l | more lists files to screen, with controls as above for more)
File size and Disk Space
ls –l | sort –n +4 list files, sort numerically by 5th field (byte size)
directories will show as small.
du –ks * space used by each file or subdirectory in current directory (size in 1KB blocks)
du –ks * | sort –n As above, sort numerically
df –h display mounted filesystems and space available
Changing Ownership and Permissions
chown user file Change ownership of file to user
chgrp group file Change group ownership of file to group
chown user:group file Do both of the above at once
chmod [ u g o ]+[ r w x ] file
Add read, write or execute permissions for user, group or world
Can be any combination
chmod [ u g o ]-[ r w x ] file
Remove read, write or execute permissions for user, group or world
Can be any combinations
chmod xyz file
Octal file permission for user (x), group (y) and world (z)
0 --- 1 --x 2 -w- 3 -wx 4 r-- 5 r-x 6 rw- 7 rwx
If changing directories instead of files, the –R flag will apply the ownerships and permissions recursively.
Process Management
cmd & Run command in background
“ctrl + z” Suspend current shell command
bg Allow suspended command to run in background
ps –e List all active processes, process ID and CPU time
ps –ef Long list of above
ps –ef | grep exp List of processes matching expression exp
kill pid Kill process number pid
kill –9 pid Kill, if above doesn’t work
killall exp Kill all processes matching expression exp
top Display processes with highest CPU usage
Tools
find . –name file1 Find file called file1 below current directory
find . –name “*exp*” Find files with names containing exp
find . –name file1 –ls Find file and display properties
find . –name file1 –exec rm {} \; Find and delete file1
cat file | mail user@company.com Mail contents of file to user
history | mail user@company.com Mail list of recent commands
(useful for phone support)
Newer versions of Linux can use the locate command instead of find. It is much better and uses an index file of the system.
Eg. # locate test.tar
Help
man cmd Bring up manual pages for cmd
man –k keyword Show which man pages relate to keyword
IRIX Specific commands
hinv Display hardware inventory
setmon change monitor settings
setmon –n 1920x1200_72 res @ Hz
setmon –x 1920x1200_72 make permanent
<ctrl + shift + / + F12> Vulcan Death Grip, kills graphics server
‘xset s on’ turns screen saver on
‘xset s off’ turns screen saver off
‘xset s 300’ turns screen saver on with 300 sec interval
|