Skip to content

Instantly share code, notes, and snippets.

@InfinityCliff
Last active July 8, 2017 01:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save InfinityCliff/8292403dd6607838e2fad9a4116474f5 to your computer and use it in GitHub Desktop.
Save InfinityCliff/8292403dd6607838e2fad9a4116474f5 to your computer and use it in GitHub Desktop.
Linux Comand Line Cheat Sheet

Linux Command Line Cheat Sheet

Copy Folder

$ cp -a source/. /dest/

The -a option is an improved recursive option, that preserve all file attributes, and also preserve symlinks. The . at end of the source path is a specific cp syntax that allow to copy all files and folders, included hidden ones.

Change Permissions

$ sudo chmod -R ugo+rw /DATA/SHARE

The breakdown of the above command looks like:

  • sudo – this is used to gain admin rights for the command on any system that makes use of sudo (otherwise you'd have to 'su' to root and run the above command without 'sudo')
  • chmod – the command to modify permissions
  • -R – this modifies the permission of the parent folder and the child objects within

* ugo+rw – this gives User, Group, and Other read and write access. As you can probably surmise, this command opens wide the SHARE folder such that anyone on the system can have access to that folder. As I mentioned earlier, a more secure method would be to use groups. But we're just using this for the purpose of demonstration.

The breakdown of permissions looks like this:

  • u – user
  • g – group

* o – other The 'other' entry is the dangerous one, as it effectively gives everyone permission for the folder/file. The permissions you can give to a file or folder are:

  • r – read
  • w – write

* x – execute Using the -R switch is important. If you have a number of sub-folders and files within the SHARE directory, and you want the permissions to apply from the parent object (the containing folder) to the child objects (the sub-folders and files), you must use the -R (recursive) switch so the same permissions are applied all the way to the deepest folder, contained within the parent.

Remove Directory

$ rm -r mydir

Unzip tar

$ >.tar.gz or tgz
$ tar xvzf ***.tar.gz
# v is for verbose

$ > .gz (.gzip)
$ gunzip ***.gz

$ >.tar.bz2 or .tbz
$ tar xvjf ***.tar.tbz

$ dtrx ***.tar.gz   
$ dtrx ***.tar.bz2 

List installed packages

$ dpkg --list  # add > **.txt to dump list to file

Show memory usage

$ df -h

usage by direcory

$ sudo du -hs /*
$ sudo du -hs /etc/*  # to restrict to specified directory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment