cd DIRECTORY PATH
move to this directory
move up a directory
move to home directory
print working directory
show all files including hidden ones
tree -L LEVEL
show directory structure with files. use the -L flag to specify how many levels into a directory to go.
ps aux | grep PROGRAM
find the process ID of a specific program
kill a certain program with its process ID
see all current processes and their cpu & memory usage as well all cpu & memory usage
exit current process in bash terminal. if no processes are current, it closes the bash window.
create multiple screens within a bash terminal, allowing you to detach processes and close out of the bash terminal and let the process run. also allows multiple bash terminals to occur simultaneously within same window. this is a more complex command and will be covered below.
create a new, blank file
cat FILE| more
read file into standard output and pipe it into more allowing you to easily scroll through it. use q to quit out of the more window.
cp FILE NEW-PATH-LOCATION
copy a file to a new location
tar -xvf TAR-FILE
decompress a tar file. the -x flag directs the command to unpack the file while -v makes it a verbose output
decompress a zip file
chmod PERMISSION-NUMBERS FILE
change the read, write, execute ownerships of a file. there is a numbering scheme to tell the command how to change the permissions. this will be detailed below.
rm -rf DIRECTORY
recursively remove a directory and all its child directories and files
remove a file
mv OLD-FILE-NAME NEW-FILE-NAME
change the name of a file
see a history of all your bash commands.
pull up a manual of the command.
HIDING AND MULTITASKING PROCESSES
screen -s SESSION-NAME
if I open Jupyter Lab, it will have an ongoing process output. if I want to use bash again, I will have to open up a new terminal session window. if I have ssh’ed into a remote machine – such as an AWS instance – and am completing a very long process, turning off my machine will kill that process. to remedy these two problems, we can use screen and its ability to “detach” windows.
we often need to have many processes going on at the same time or need to reference a terminal output. one could have many terminal sessions open. to remedy this, we can use screen and its ability to create new “windows” within a terminal session, name them, switch between them, and even display them within the same terminal session window as different panes.
screen -S SESSION-NAME
#List all detached screens with ID numbers screen -ls #Reattach a screen with ID number screen -r ID-NUMBER
chmod NUMBER-SCHEME FILE
the general command goes as follows:
|chmod 400 FILE||read by owner|
|chmod 004 FILE||read by all|
|chmod 200 FILE||write by owner|
|chmod 002 FILE||write by all|
|chmod 100 FILE||execute by owner|
|chmod 001 FILE||execute by all|
each digit place has a meaning:
|Digit 1||Sets user or group ID|
|Digit 2||Sets permissions for file owner|
|Digit 3||Sets permissions for other users in file group|
|Digit 4||Sets permissions for other not in file’s group|
and each digit value has a meaning:
now if you want to do multiple things, you add all the digits up for each digit place. if you want it to be writable by all, executable only by the owner, and readable only by the group, you get 002 + 100 + 040 = 142
you can also use a letter scheme:
|u||user who owns|
|rwx||read, write, execute|
thus chmod u+rwx means the owner can read, write, and execute.
KILLING AN UNRESPONSIVE PROGRAM
ps aux | grep PROGRAM-NAME
once in a while, a program will become unresponsive and you need to kill it. linux doesn’t have the windows equivalent of task manager or the macOS force quit. instead, in linux you can find the process ID of the program and then use that ID number to kill it.
ps shows a snapshot of current processes. you can pipe it into grep with a name of a program. the name does not have to be totally correct, though it helps. it will then show processes it thinks match the name. it should have a processes ID number to the right of it. typing kill and then this ID number will kill the program.
often in bash, i want to repeat past commands. but I don’t want to have to rewrite the entire command again, especially if it’s long. if you type and enter the history command, it will show you all your past commands. there will be a number to the left of each command. if you type ! and then that number, it will repeat that command for you.