Unix Cheat Sheet

ADVERTISEMENT

Archives and Extracting
Unix
CHEAT SHEET
tar zxvf file.tar.gz - extract file.tar.gz
Getting Help
tar jxvf file.tar.bz2 - extract file.tar.bz2
tar cf file.tar file1 file2 file3 - create file.tar
man command - view the manual for command
that contains file1 file2 and file3
tar czf file.tar.gz folder - create file.tar.gz with
Files and directories
the contents in folder
zip -r myzip.zip folder - create myzip.zip with the
pwd - print working directory
contents in folder
ls - view files in working directory
unzip myzip.zip - unzips the file myzip.zip
ls -l - view files in a list
ls -la - list all files in a list, including hidden files
File permissions
cd dir - change directory to dir
cd or cd ~ - change to home directory
chmod options file
cd / - change to root directory
cd .. - go one directory up
Definition
Options
cd - - go to the previous directory
u
owner
rm file - remove file
group
g
rm -r dir - remove directory dir
o
other
rm -rf dir - forcefully remove directory dir
execute
x
rmdir dir - remove empty directory dir
w
write
mkdir dir - make directory dir
read
r
ln -s file link - create a link to file
+
add permission
cp file1 file2 - copy file1 to file2
remove permission
-
cp -r dir1 dir2 - copies all of dir1 into dir2
=
set permsission
mv file1 file2 - rename or move file1 to file2
chmod g+x file - add group execute bit
cat file - output contents of file to the terminal
less file - view file (press 'q' to exit)
chmod u-x file - remove user execute bit
chmod o+wx file - add other write and execute bit
head file - output the first 10 lines of
file
tail file - output the last 10 lines of file
chmod ugo+rwx file - add read, write and execute for everyone
tail -f file - watch file grow, starting with the
Command Expressions
last 10 lines
./ - current directory
Remote Connections/File Transfers
./app - runs app in your current directory
; - run several commands sequentially
ssh user@hostname - login to hostname as user
mkdir test; cd test
ssh -p W user@hostname login to hostname as user on port W
&& - run command only if the previous command succeeds
scp file user@hostname:/place/for/file - transfer file to
./configure && make --prefix=/home/user && make install
hostname as user, store in /place/for/file
|| - run command only if the previous one fails
scp user@hostname:/some/file file - transfer /some/file
ping || echo "Google is down!"
from hostname as user and store it as file on local machine
| - pipe, send output of one command to another command
Searching
ls | sort
> file - write stdout to file
>> file - append stdout to file
grep 'STRING' file - searches for 'STRING' in file
< file - read file into stdin
grep -r 'STRING' dir - search in files recursivley for
& - run command in background
'STRING' in dir
xterm & - opens a new xterm in background
command | grep 'STRING' - filter for 'STRING' in the
`command` - runs command, output can be used in other commands
output of command
export HOME=`pwd`
find dir -name 'myfile' - search in dir for 'myfile'
* - wildcard: match zero or more characters
find . -name 'file.*'
? - wildcard: match single character
find . -name 'file??.txt'

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go