Linux Commands Cheat Sheet

Linux commands are kind of hard to remember, that is why working with terminal seems to be scary at the beginning.  But it is perfectly OK,  you start using the command line and you learn little by little though sometimes you forget the commands or the syntax of those commands! So you can do copy paste !

Linux commands are same for Linux mint, Kali Linux, Ubuntu and etc., you gonna need a cheat sheet to help you learn and remember them.

If you are not sure how to use these commands please feel free to see video I made. It really teaches you how to use terminal and Linux command line. (click here or see embedded at the bottom of the page )

Most Basic Commands

cdchange folder
  cd ~home
   cd ..parent folder
   cd /root folder
ls -lha List directory (long)(human)(all)
Equivalent to dir in windows
pwdCurrent path
mkdir xyzmake directory xyz
mv  ~/from  /to/   move file
~/ and /  are examples see cd
you can use mv for rename!
cp -ar ~/from  ../to/   copy all
~/ and ../  are examples see cd

Text Files :

cat file.txtShow content
cat file.txt | less   with paging
less file.txtShow content with paging
echo ‘A string’Outputs : A string
echo $USEROutputs user name
echo $HOMEOutputs home path

Use it in bash scripts to give input to other command :

Ex : echo ‘Some text’ > xyz.txt        
above make a file called xyz.txt with content some text

Remote Connection / File Copy

Linux does not have remote desktop as windows, but don’t worry Linux commands does the jobs perfectly. Sometimes you need to connect to another Linux server using terminal and/or copy file from one Linux system to another Linux system via network. there are applications that help you with that (specially if you are running windows and want to connect to a Linux system ) Putty for connection and WinSCP is for transferring file. But you can use Git bash in windows with these command (or you can run them directly in on Linux client)

Remote connection

ssh user@192.168.4.23  remote connection
ssh -i key.pem  user@192.168.4.23 with key

Copy Files

scp -i publicKey.pem  myfile.txt remoteuser@remoteserver:/remote/folder/   local 2 server
scp -i publicKey.pem  remoteuser@remoteserver:/remote/folder/remotefile.txt  localfile.txt  server2local

Archive – Compress / Extract

tar -cvf songs.tar ./folder (create)(verbose)(filename)
-cvzf -gz (gzip)  OR -cvjf -j (bzip2)
tar -xvf songs.tar -C /target/directory(extract)(verbose)(filename)
-xvzf  (gzip)   OR  -xvjf (bz2)

Permission In Linux

In Linux there is 3 type of access owner (single user) group and everyone. The weird thing is that owner does not has full permission but that is defined (r : read , w: write, x: execute). most people mix up two of Linux commands namely chmod and chown . the first one is to assign permission , the latter is for assign user and group (that has that permission)

NOTE : Don’t forget to restart your service when you change permissions and users (services that need access to files and folder like ftp, NginX, apache, K8s and …)


File Permissions (chmod)

chmod -R 765 /dir
[owner][group][others] ===> Numbers ==>

rwxrwxrwx      [owner][group][others]

0: No permission4: Read
1: Execute5: Read and execute
2: Write6: Read and write
3: Write and execute7: Read, write and execute

Assign user and group (chown)

chown user:group example.txt

Working with user

Here are Linux commands for working with users and groups

adduser username    //  adduser username
addgroup groupname
usermod -a -G groupName userName

Archive – Compress / Extract

Remember: Tar just put everything is a single file if you want to compress you need to combine it with gzip (or bzip)

tar -cvf songs.tar ./folder (create)(verbose)(filename)
-cvzf -gz (gzip)  OR –cvjf -j (bzip2)
tarxvf songs.tar -C /target/directory (extract)(verbose)(filename)(extract)(verbose)(filename)
-xvzf  (gzip)   OR  -xvjf (bz2)

Utilities

curl www.me.combrowser
wget ww.com/file.tardownload

Nano xyz.txtEditor
vim xyz.txt Editor
 htop  Get stats
lsblkList Disks

Make Private key single line

Sometimes you need to use private key as single line (for example when you are using it in settings) here is how to do it.

awk -v ORS='\\n' '1' private-key.pem | cat

Posted

in

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *