Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
quick commands I use frequently in linux but always forget the syntax

Quick Reference Linux Commands

Find string in files in directory

find . | xargs grep 'string' -sl
sudo find / | xargs grep '' -sl

Find case insensitive

find / -iname 'wOrDs'

Find directory name

find . -type d -name "audit" -ls

Sort files in a dir by size

ls -l -S
du -h | sort -nr
du -ksh /*
du -ksh * | sort -nr

Find top 10 largest files on root

sudo du -a / | sort -n -r | head -n 10

Sort files in a dir by date

ls -lrt
# (Same but reverse)
ls -l --sort=time

Show nix distro

# Show ubuntu distro
cat /etc/issue
Ubuntu 14.04.1 LTS \n \l

# Show centos distro
cat /etc/*release | grep release
# Show RedHat distro
cat /etc/redhat-release

Disable service Ubuntu

sudo update-rc.d tomcat disable

TAR and GZIP a directory

tar -zcf archivename.tar.gz /my/dir

TAR and GZIP files

tar zcfv messages.rollup.20151016_0850.tar.gz messages-20140*

Count number of files in directory recursively

ls -Rl | wc -l

Delete files older than 3 days in current directory recursively

find . -type f -mtime +3 -exec rm {} \;

Remove windows line endings in vim

:set ff=unix

Grep showing back X number of lines

grep -B 3 -A 2 foo README.txt

Remove lines containing comment with sed

sed -i '/\#/d' ./*.log

Show number of cores


Download GitHub Tarball from Branch and Unzip

curl -L > collectd-cloudwatch.tar.gz && tar -xvzf collectd-cloudwatch.tar.gz

SFTP With Identity FIle

sftp -o "IdentityFile=keyname"
## Show number of procs per user
`ps haux Ou | cut '-d ' -f1 | uniq -c`
## Run a command as another user
`runuser -l  userNameHere -c '/path/to/command arg1 arg2'`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.