Skip to content

Instantly share code, notes, and snippets.

@ctufts
Last active March 1, 2023 20:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ctufts/aa89e059084898667ebff98673a6fe1c to your computer and use it in GitHub Desktop.
Common linux commands

Ubuntu Linux

  • sudo -i : elevate to super user
  • du : get breakdown of memory usage of all subdirectories
  • df -h : get breakdown of memory usage on disk
  • ls -a : show all files in directory (including hidden files)
  • rsync : copy files from one server to another (similar to scp but more functionality)
    • Set up rsync with sudo
    • rsync -az -e "ssh" --rsync-path="sudo rsync" user@servername:/pulled-source-directory /local-directory/
    • rsync [source] [destination]
      • can pull or push data (source or destination can be ssh connection)
  • adduser <username> : add new user
  • gpasswd -a <username> sudo : give user sudo privelages
  • rm -r <directory name> : remove directory and all files in the directory recursively
  • lshw : Get machine specs
  • cut -d, -f1 --complement <csv file name > : remove first column of a csv file (change f flag's number for different lines)
  • kill $(ps aux | grep '[p]ython csp_build.py' | awk '{print $2}') find and kill all processes with a given name. Reference link
  • grep -rnw '/path/to/somewhere/' -e "pattern" : search for text pattern in files recursively and return the line number in the file (-w match the whole word, -r recursive, -n line number)
  • wc -l <filename> : get number of lines in a file
  • ls -ld /proc/<pid> : Get the time/date when a process (pid) was started
  • ls -d */ : List directories only
  • find <directory name> -type f -print0 | xargs -0 grep -l "search term" : search a directory of files for all files containing the string "search term"
  • Notes about PATH:
  • export PATH="$PATH:/data/anaconda2/bin" : Add to PATH variable
  • source ~/.bashrc : reload the .bashrc file (same goes for altering the zshrc, etc.)
  • echo $PATH : print path variable to terminal
  • Note on removal from $PATH :
    • echo $PATH variable, find the part you would like to remove, then redefine/export $PATH without that component (probably a better way, but this works)
  • service --status-all : check status of all services
  • service <service name> status : check status of a specific service (may require sudo)
  • ctrl + r : search command history
  • cd - : go to previous directory
  • find . -type f -name "*.ipynb" : search all subdirectories and current directory for file ending with ipynb
  • find . -type d -name "directory name" : search all subdirectories and current directory for directory by name
  • ssh -i ~/.ssh/key_file user@servername : ssh specifying specific key
  • ls | wc -l : number of files in current directory
  • crontab -l : list all cron jobs for current user
  • find / -mount -type f -printf "%s %h/%f\n" | sort -n -r -T /datadrive | head -n 100 - searches a partion for files and sorts them by memory usage, -T flag lets you specify another partition for sort to use in the case that the partion you are searching is out of space, head provides the top 100 largest files.

Redhat Linux

  • cat /proc/cpuinfo : machine specs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment