Linux command cheat sheet
In this cheat-sheet file usually means file or directory ~ is a linux short-hand for your home-directory
Command |
Description/explanation |
Useful options |
Examples |
---|---|---|---|
ssh |
secure shell - remote login to another linux machine |
ssh ola@saga.sigma2.no |
|
hostname |
Given name to machine |
||
cd |
change directory – move around in your file hierarchy |
cd ~/documents |
|
pwd |
print working directory |
||
ls |
List – list content of directory |
-l,-lh |
ls documents |
echo |
print out something |
echo “Hi there” |
|
mkdir |
Make directory |
-p |
|
cp |
copy |
cp file1.txt ~/documents/file2.txt |
|
mv |
move |
mv file1.txt ~/documents/file2.txt |
|
rm |
remove |
-f, -r, -i |
rm -i file1.txt |
cat |
Cocatenate – used to view contents of a text file |
cat file1.txt |
|
more |
View text file in command promt, move |
more file1.txt |
|
less |
Similar to more – but you can move |
less file1.txt |
|
head |
Print out top N lines of text file |
-n |
head file1.txt |
tail |
Print out bottom N lines of text file |
-n |
tail file1.txt |
diff |
Print out differences between files |
diff file1.txt ~/documents/file2.txt |
|
wget |
Download files from the internet |
wget https://www.nrk.no |
|
tar |
Archive or unarchive files |
xvf (x: extract v: verbose f: filename) |
tar xvf demo-moving-around.tar.gz |
find |
Find files in the file hierarchy |
find file1.txt ~/ |
|
touch |
Create, modify and change timestamps of a file |
touch newfile.txt |
|
grep |
Searches through files and prints out |
grep car texaboutcars.txt |
|
bash |
Sh-compatible command language interpreter |
||
chmod |
change mode – change permission mode |
-R |
chmod u+x file1.exe |
sort |
Sort the given input |
||
uniq |
Filters out repeated occurences |
||
wc |
Word count |
-l,-c,-m |
wc textaboutcars.txt |
history |
Show bash history |
||
xargs |
Build and execute command lines |
||
man |
Linux manual – all linux commands have |
man ls |