Skip to content

Instantly share code, notes, and snippets.

@Atlas7
Last active June 9, 2017 14:37
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 Atlas7/c40c25bd173ec1b780224bb790dd1c41 to your computer and use it in GitHub Desktop.
Save Atlas7/c40c25bd173ec1b780224bb790dd1c41 to your computer and use it in GitHub Desktop.
ubuntu / Linux command cheatsheet

Background

I am primary Mac user (MacBook Pro), and a secondary Windows / Linux User. I have a pretty powerful Windows 10 gaming PC with Nvida Graphic card) which I have recently turned into a Dual-bootable machine (bootable between Windows 10 and Ubuntu 16.04 LTS). Given I am a pretty new Ubuntu user I very frequently have to look up commands to perform certain actions. this post aims to serve as my personal cheatsheet (for Ubuntu commands).

Machine Specs:

  • (Rough) MacBook Pro Spec: El Capitan, i7 CPUs, 1TB HDD, 16 GB RAM, Intel Graphic.
  • (Rough) Gaming PC Spec: Dell XPS 8700, i7 CPUs, 16 GB RAM, 2TB HDD, onboard Intel Graphic card plus with a physical Nvida GeForce GTX 750 Ti Graphic Card).

Handy Commands

Here are some commands that are slightly beyond basics, but ultra handy.

How do I find out the model of my graphics card?

lspci | grep VGA to see if my NVIDIA 750Ti is detected.

ls -dl [ac]* - lists out only the directories beginning with the letter a or c at the current path Stackoverflow

cd - - go back to the previous directory. (it's sort of like back one page in a browser.)

ls -lh - list files within the current directory. The h shows the size of file / folder in a human readable format (kilo- / mega / giga / etc bytes). append these: a: show hidden file, d show directory only.

find . -name doc | wc -l - within the current directory, recursively find all files beginning with the string 'doc', then count & display observations.

Package mananager related:

  • apt-get is high level package manager. dpkg is low level package manager.
  • sudo apt-cache search lynx - search the lynx package on APT.
  • sudo apt-get install lynx - install the lynx package (along with dependencies)
  • sudo apt-get remove lynx - remove the lynx package (and leave the dependencies alone). This is a safe option.
  • sudo apt-get autoremove lynx - remove the lynx package AND remove the dependencies (if not used by other packages). This is cleaner (providing you trust the publisher) but might cause problems. Avoid this.
  • sudo apt-get upgrade - update all installed packages.

yelp man:cat - brings up the man page for the cat function via a GUI.

Processes related

  • ps, ps -ef, ps -eLf
  • pstree | head -10 - ps in graphical form.
  • top - realtime load avearges and processes

(press following keys while using top)

key action
t Display or hide summary information (rows 2 and 3)
m Display or hide memory information (rows 4 and 5)
A Sort the process list by top resource consumers
r Renice (change the priority of) a specific processes
k Kill a specific process
f Enter the top configuration screen
o Interactively select a new sort order in the process list

Scheudling related

  • crontab -l to display cron jobs
  • crontab -r to cancel cron jobs
  • crontab mycrontab to load the cron job from a bash script mycrontab
  • at

Networking related

  • host linuxfoundation.org - gives you the ip address of a web address.
  • nslookup linuxfoundation.org - shows you domain name info.
  • cat /etc/hosts - shows you the machine-IP mapping info.
  • cat /etc/resolv.conf - shows you the dynamically resolved IP of your network.
  • Lab: Network Troubleshooting - step-by-step guide.

Scripting related

  • If Else condition
  • Linux condition testing bracket
  • myLen1=${#string1} - Saves the length of string1 in the variable myLen1.
  • TEMP=$(mktemp /tmp/tempfile.XXXXXXXX) - create a temporary file.
  • TEMPDIR=$(mktemp -d /tmp/tempdir.XXXXXXXX) - create a temporary directory

printing related

  • cups package handles printing.
  • ls command relates to printing from terminal.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment