Skip to content

Instantly share code, notes, and snippets.

@rendicott
Last active January 18, 2022 12:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rendicott/ef1844608a7932cea2becdda6983d27d to your computer and use it in GitHub Desktop.
Save rendicott/ef1844608a7932cea2becdda6983d27d to your computer and use it in GitHub Desktop.
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 'http://127.0.0.1:4567' -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
:wq

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

nproc

Download GitHub Tarball from Branch and Unzip

curl -L https://github.com/GESkunkworks/collectd-cloudwatch/tarball/feature/addDimensions > collectd-cloudwatch.tar.gz && tar -xvzf collectd-cloudwatch.tar.gz

SFTP With Identity FIle

sftp -o "IdentityFile=keyname" jay@server.name.com
uname-st@securetransport.ec.equifax.com

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'

Fix AWS SSM PAM issue

cp /etc/security/access.conf /etc/security/access.conf.2020-01-27
sed -i '/ALL : ALL/i + : ssm-user: ALL' /etc/security/access.conf
grep ":" /etc/security/access.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment