This is a draft cheat sheet. It is a work in progress and is not finished yet.
Common
pwd |
pinrt current working dir |
cd |
change directory |
cd ../ |
change directory up 1 |
cd ~/ |
change dir to home. |
ls |
list content of directory |
ls -l |
detailed list |
ls -h |
readable byte format |
ls -F |
list all files + extension attributes |
ls -lF |
list files, ext, attrib, size, etc -> more detailed |
tree |
list directory in a tree like format |
file |
file command displays type of any file |
file Desktop |
will return Desktop: Directory |
alias |
to list all current alias for system/user |
alias LC="newFunction" |
creates a new alias "LC" that does "newFunction" |
man |
man pages |
man -k |
very similar to apropos |
apropos |
list all available man pages for specific word |
Text + Redirection Examples
echo "string" |
sends string to stdout (terminal) |
echo "string" > file1.txt |
sends string to file1.txt (redirection) |
echo -e "string \tNewString" |
-e = enables extra character (?) use. \t option is for tab -> writes NewStringAfterTab after a tab, not space! |
echo -e "string \nNewString" |
same as above but writes newstring after newline instead of tab. |
cat |
reads content of txt file and sends it to stdout (terminal) |
cat > file.txt |
with redirection before any file is mentioned -> will allow you to enter text at Terminal screen until Ctrl+d command (end) and sends it to file.txt |
cat <<exit> |
same as above but need to type exit as end command instead of Ctrl+d |
cat file1.txt > file2.txt |
reads content from file1.txt, sends it to file2.txt AND replaces any content! |
cat file1.txt >> file2.txt |
appends content of file1.txt to end of file2.txt |
tac |
same as cat but reads file in reverse! |
head |
show first 10 line of a file |
head -n (X) |
show the first X lines of a file |
tail |
show last 10 lines of text file |
tail -n (X) |
show last X lines of text file |
more |
displays first page of file |
less |
displays the last page of a file and allows to move through pages with enter + spacebar |
Wildcards
* |
Matches 0 or more occurrences of the previous character |
Common |
? |
matches 0 or 1 occurrences of the previous char |
Extended |
+ |
matches 1 or more occurrences of prev char |
Extended |
. |
Matches 1 character of any type |
Common |
[...] |
Matches 1 character from the specified range |
Common |
[^...] |
Matches 1 character NOT from the range specified within braces |
Common |
{ } |
Matches a specific number or range of the prev char |
Extended |
^ |
Marches the following characters if they are the first characters on the line |
Common |
$ |
Matches the previous characters if they are the last char on the line |
Common |
(...|...) |
Matches either of two sets of characters |
Extended |
misc
echo $PATH |
see the content of the $PATH variable currently loaded in memory |
which "grep" |
to search directories of the PATH variable for a file called grep. |
ln (link) |
command to hard-link files |
ln -s |
command to create a symbolic link between 2 files |
whoami |
find out which user you are logged on as |
groups |
lists groups for current user unless we specify a user |
cat /etc/group |
to list all groups that exists on the current system |
chown |
change user |
chown -R |
change owner/permissions recursively (-R) |
chgrp |
change group command |
Permissions
chown |
change owner |
chgrp |
change group |
chmod |
change mode of file (permissions |
u |
user |
g |
group |
o |
other |
a |
All categories |
+ |
adds a permission |
- |
removes a permission |
= |
makes a permission equal to |
chmod u+w file1 |
change user permissions to write for file1 |
rwx |
4+2+1 = 7 |
rw- |
4+2 = 6 |
r-x |
4+1 = 5 |
r-- |
4 |
-wx |
2+1 = 3 |
-w- |
2 |
--x |
1 |
--- |
0 |
Compression + Exatraction
compress -v file1 file2 |
compresses file1 into file1.z and file2 into file2.z |
zcat compressedfile1.z |
command to display contents of a compressed file |
uncompress -v |
command to uncompress the file |
gzip -v file1 |
compresses fil1 with gzip utility (better compression ratio) to file1.gz |
gunzip -v file1.gz |
to decrompress a .gz file |
bzip2 -v file1 |
compress file1 using bzip2 utility to file1.bz2 |
bunzip2 -v file1.bz2 |
uncompress command |
tar |
tape archive utility. Used for backups and compression! |
tar -cvf /backup.tar * |
command to create an archive called backup.tar that contains the contents of the current directory |
tar -tvf /backup.tar |
command to view the contents of an archive |
tar -xvf /backup.tar |
extract the contents of the archive to our current directory |
tar -zcvf /backup.tar.gz* |
creates a gzip-compressed archive called /backup.tar.gz that contains the contents of the current directory |
tar -ztvf /backup.tar.gz |
to view the contents of a gzip-compressed archive |
tar -zxvf /backup.tar.gz |
to extract contents of a gzip-compressed archive |
cpio |
similar to tar utility |
|
|
Directory + files
mkdir |
make directory |
rmdir |
remove directory -> unlike rm -rf |
touch |
can be used to create file.txt |
rm |
remove file |
rm -rf |
DELETE ALL! -> remove files recursively and force it |
rm -i |
-i ooption to prompt for removal before deletion |
mv file1.txt Newfile.txt |
Ironically -> command to rename files. Rename file1.txt to Newfile.txt |
cp /dir/file1 /newdir/file1 |
copy command to copy file1 from dir to newdir |
File search + Manipulation
find |
find for files in a directory hierarchy |
locate |
find files by name |
cut |
with options -> can cut out sections and fields of a text file and send it to stdout |
cut -d ' ' -f (X) |
-d = delimiter option. Anything that seperates the first field by the delimiter will be counter as 2...3...4...5 in field. -f = field option. |
date |
sends out the current date to stdout. Useful with redirections |
grep string file.txt |
look for anything that contains string in file.txt |
grep -i string |
return any hit that matches string exactly |
grep -i string |
Can also be used to exclude case sensitiveness |
grep -r string |
-r = looks for string recursively down all files in the current directory tree. |
grep -c 'string' Test.txt |
Returns the numbers of instances of string in Test.txt. Similar to wc (word count) command |
grep -v string text1.txt |
-v option -> return lines that do not contain string |
grep -e |
extended grep - same as egrep |
egrep |
extended grep |
egrep "(lodge|lake)" text1.txt |
View lines that contain either lodge of lake. |
sed |
stream editor -> can be used instead of cut & to search + replace. |
sed -i -e 's/few/asd/g' Test.txt |
replace all instances of few in the file Test.txt with 'asd'. Find and replace command |
Vi Commands
vi text.txt |
opens text.txt in VI editor |
i |
enter insert mode |
a |
Changes to insert mode & places cursor after the current character to enter text |
o |
Change to insert and opens new line beneath current |
I |
changes to insert mode and places cursor at start of current line |
A |
Changes to insert mode and places cursor at end of line |
Escape |
leave insert mode |
$ |
go to end of line in reg mode |
:wq |
save and exit |
:q! |
exit and do not save |
ctrl+shift+v |
paste keyboard shortcuts |
G |
move the cursor to last line of document |
x |
deletes character cursor is on |
d$ |
deletes the cursor character to the end of the line |
u |
undo the last function |
. |
repeats the last function |
y$ |
Copies the current line into a temporary buffer in memory for later use |
p |
Pastes the content underneath current line or after current word |
P |
Pastes content above current line or after current word |
w filename |
Saves the current document to file named filename |
:r !date |
reads output of date command into document under the current line |
:set all |
displays all vi environment settings |
:s/the/THE/g |
searches for reg expression "the" and replaces each occurence globally throughout the current line with the word "THE" |
:1,$ s/the/THE/g |
same as above but does this globally from line 1 to the end of the document |
filesystem
cat /dev/proc |
show all devices currently used by the system & it's major number |
mount |
mount command |
mount -t |
to specify which filesystem to be mounted use -t option |
umount |
unmount command |
mkfs |
make filesystem command |
mkfs -t ext |
use -t command + filesystem chosen to specify filesystem to be used |
mke2fs |
make ext2 file system. |
fuser -u |
to check if a directory or device is currently used by a user |
cat /etc/fstab |
list contents of fstab file which is file to edit to add devices to auto-mount at boot. |
mkisofs |
make iso image command |
fdisk |
partitioning utility |
cdisk |
Same as fdisk but with GUI |
pvcreate /dev/sda4 |
creates physical volume |
vgcreate vg00 /dev/sda4 |
create volume group |
lvcreate -L 5GB -n Data vg00 |
create logical volume named Data that's 5GB in size. |
df |
disk free space command (shows free space on all mounted filesystems) |
df -h |
readable format |
du |
directory usage -> useful to know which directory is using up the most space |
fsck |
filesystemcheck |
lsblk |
list block devices (including Partitions) |
|