Skip to content

Instantly share code, notes, and snippets.

@dcchambers dcchambers/cli.md
Last active Mar 5, 2019

Embed
What would you like to do?
Commonly used Linux/Unix commands and programs one should be vaguely familiar with. Not an exhaustive list of all tools - just a list of the essentials.

File/Directory Management

  • touch
  • ls
  • ln
  • cp
  • mkdir
  • mv
  • rm
  • rmdir
  • which
  • readlink

Viewing/Searching Files:

  • cat
  • tail -f
  • less
  • more
  • watch
  • diff
  • grep
  • find
  • wc -l
  • lsof

Permissions/User Account

  • chmod
  • chown
  • useradd, userdel
  • passwd
  • /etc/passwd, /etc/shadow, /etc/group /etc/gshadow

Remote File Transfer

  • ssh
  • scp
  • ftp/sftp
  • rsync
  • wget
  • curl

File System Commands

  • lsblk
  • fdisk
  • du
  • df
  • fsck
  • mkfs
  • mount, umount

String Manipulation

  • sed
  • awk
  • tr

Git

  • git
    • init pull push fetch commit branch checkout merge cherry-pick log status add rm diff ...
    • git diff <COMMIT HASH>^ <COMMIT HASH> allows you to view the changes of a specific git commit. Can also use git show <COMMIT HASH>.
    • git log --graph --decorate for a colorful visual git log.

Networking

  • dig
  • traceroute
  • ip r ip a ip link ...
  • ping
  • netcat nc
  • nslookup
  • tcpdump
  • iptables
    • ufw
    • firewalld

System and Processes

  • service
  • systemctl
  • ps commonly used with -aux or just aux
  • top

Misc. Commands

  • Search for an installed package/library: ldconfig -p | grep <package/library> or whereis <package/library>
  • mdadm for managing linux software RAID.
  • sort
  • uniq most commonly uniq -c
  • tar -xzvf <name-of-archive.tar.gz> extract a .tar.gz archive.
  • tar -czvf <name-of-archive.tar.gz> </path/to/directory-or-file> create a .tar.gz archive.
  • lspci lscpu
  • dmidecode
  • lshal - Get lots of hardware information (including some dmi info) without needing root access.
  • uname -r Print the Kernel Release. Can also do cat /etc/*release* to check Linux distro/version.
  • xargs -I% -P <Threads> -n <Max Args> Allows you to run multiple commands in parallel.
  • socat
  • visudo - Edit the /etc/sudoers file.
  • modprobe - Add or remove modules from the Linux kernel.
  • dkms - Rebuild dynamic kernel modules.
  • ipmitool Used to query ipmi data and controlling ipmi devices. ipmitool sdr dumps sensor data.
  • tee
  • tar
    • tar -cvf archivename.tar /path/to/directory - Create an .tar archive of a directory.
    • tar -xvf archivename.tar - Extract (unpack) the .tar archive.
    • Add the -z flag to both commands to compress (gzip) the archive.

Useful (Bash) Tricks

  • Use | to pipe the results from one command into another (e.g. cat names.txt | sort)
  • Stream redirection
    • < - Overwrite standard input
    • << - Append standard input
    • > - Overwrite standard output
    • >> - Append standard output
  • history - View bash history.
    • You can then type !<number> to enter that command from your bash history.
  • Ctrl+R - Search through bash history. Begin typing a search query, and can press Ctrl+R again to view more matches.
  • -- two dashes signifies the end of command options, and allows you to specify "-" options as regular arguments.
    • e.g. cat -- -z would print out the contents of a file named "-z" while cat -z would print an error.
  • & Add an ampersand after a command to make it run in the background.
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.