Common bash commands

typing this at the promptdoes this

ctrl + r (on a Mac)

allows you to search your terminal for previous commands…just start typing

tar -xvzf [fileName.tar.gz]

unzip a .tar file

standard would be ls and ls -l, but lsd and lsd -l is way better 🙂

list all files and folders in your working diretory with info on permissions

standard would be du -a -h --max-depth=1 | sort -hr, but dust is way better 🙂

lists all files and folders in your working directory sorted by size

standard would be du -sh *, but dust is way better 🙂

simpler version of the command above. lists all files in a folder and shows their file size

standard would be df -h, but duf is way better 🙂

view free/used disk space by drive

lsd -l | wc -l

counts ALL files in a directory

lsd -l | grep -c 'sam’

counts ONLY files in a directory that are of a certain type (in this example, .sam files)

lsd -l -t | head -n1

shows only the most recently modified file or directory in your current working directory

ls -X

group files in directory by file type (extension)

tree -d, but broot is way better 🙂

lists all files and folders in your working directory as a tree structure

lsblk

lists drives and their size (as well as used/free space on each)

pressing up arrow

recalls previous command

cd /

takes you to the root directory

cd ~

takes you to your home directory

cd ..

takes you up one level in your file directory

cd ../..

takes you up two levels in your file directory

chmod u+x [fileName]

edits permissions on file

chown [yourUserName] [fileName]

makes you the owner of a file

chgrp [yourUserName] [fileName]

assigns you as the group for the file

rm -rf [directoryName]

removes a folder and all of its contents

wget [URLtoFile]

downloads a file from a website

defaults write com.apple.finder AppleShowAllFiles YES

show all hidden files in the finder (Mac only)

pip freeze

lists all the python packages (and their versions) installed on the server

sudo nano /etc/profile

opens up the system profile where new program paths can be added to the system PATH

export PATH="/path/to/your/software/:$PATH"

add a new piece of software to the system PATH so it is executable from anywhere

alias something="something else"

add lines like this to your ~/.bash_profile to create a keyboard shortcut, in this case typing 'something' actually does 'something else'

progress or watch progress

displays the progress of file manipulation jobs (e.g. from cp, mv, etc)

whereis

locates the binarysource, and manual page files for a command.

micro [FILENAME]

Micro is a text editor built right into the terminal. You can call ‘micro’ and any text file by name to open and edit that file. Micro is particularly nice since it has some of the ease of. use you are probably arelady familiar with for stand-alone text editors. User-specific customization of micro’s settings can be done by modifying the config file that lives at /home/[USERNAME]/.config/micro/settings.json

Ctrl + R

Lets you search your bash history to quickly recall commands

htop

monitor CPU and RAM usage for all jobs being run on the server

nvidia-smi

monitor GPU usage

column -s, -t < somefile.csv | less -#2 -N -S

the column program lets you view csv and tsv files with proper display directly in the terminal