Linux Cheatsheets

Fri, Jun 24, 2016 Last Modified: Jul 7, 2016
Category: cheatsheet Tags: [linux]

Linus Penguin Quote

Linux Commands Cheatsheet

ls - list directory contents

SYNOPSIS
       ls [OPTION]... [FILE]...
       -a, --all
              do not ignore entries starting with .    
examples effects
ls -la list all file/directories including hidden in long list form
ls -ld list directory only in list form
du - estimate file space usage
SYNOPSIS
  du [OPTION]...  [FILE]...
  -c, --total
              produce a grand total
  -h, --human-readable
              print sizes in human readable format (e.g., 1K 234M 2G)
  -s, --summarize
              display only a total for each argument
  -a, --all
                write counts for all files, not just directories
examples effects
du -sch folder/ folder/ size
du -sh * sizes of all folders and files in current directory
du -ahd1 sizes of all (including hidden) in current directory
note pipe to | sort -h[r] for result sorting
df - report file system disk space usage

SYNOPSIS
       df [OPTION]... [FILE]...
examples effects
df -h disk usage in human readable form

example output

Filesystem      Size  Used Avail Use% Mounted on
udev            990M  8.0K  990M   1% /dev
tmpfs           201M  944K  200M   1% /run
/dev/sda1        17G  6.3G  9.8G  40% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none            5.0M     0  5.0M   0% /run/lock
none           1001M   23M  978M   3% /run/shm
none            100M   44K  100M   1% /run/user
Dropbox         238G  116G  123G  49% /media/sf_Dropbox
/dev/sr0         57M   57M     0 100% /media/user/VBOXADDITIONS_5.0.14_105127

Check system info

$lscpu # check cpu info
$cat /etc/redhat_release # find redhat version
$unmae -rs # kernel release version and name

To check memory usage

commands effects
free -h short summary
cat /proc/meminfo show meminfo file
top show ram cpu usage per process, press e to scale units

To put a process (e.g., mongod) to background,

$ ^Z # ctrl + z to stop mongod
[1]+  Stopped mongod
$ bg
[1]+ mongod &
$ mongo
> ^C # can successfully connect
$ fg
mongod
^C
$ # back to bash
chmod - change file mode bits

SYNOPSIS
       chmod [OPTION]... MODE[,MODE]... FILE...
       chmod [OPTION]... OCTAL-MODE FILE...
       chmod [OPTION]... --reference=RFILE FILE...
examples effects
chmod +x file permit the file as executable
chmod 777 file make the file globally readable, writable, executable by all users, groups, owner

Shortcuts

Open Application

|Application|key binding|Desktop Env|Key binding|DE| |Terminal|shift+ctrl+N|Gnome|ctrl+alt+T|typical|

Command Line Shortcuts

References:

meta key: Esc on mac

key binding Action
ctrl+a/e move cursor to line beginning/end
meta-f/b move cursor one word forward/backward, right/left
ctrl+u/k delete from cursor to line beginning/end
ctrl+w, meta-d delete one word from cursor left/right
meta-t transpose two words before cursor, or transpose one before one after
ctrl+y yank/paste previously killed text
ctrl+_ undo last edit

When connecting from mac terminal via ssh to linux box, it behaves kind of like vim, maybe vi. Esc to change mode, w/b to move forward backward, etc

comments powered by Disqus