From 082337ddad0743ba78e075d4321bc31a860dc522 Mon Sep 17 00:00:00 2001 From: Porter Libby <pelibby16@earlham.edu> Date: Tue, 4 Feb 2025 16:19:53 -0500 Subject: [PATCH] update bash example --- cs-fundamentals/bash-reference-example.md | 86 +---------------------- 1 file changed, 3 insertions(+), 83 deletions(-) diff --git a/cs-fundamentals/bash-reference-example.md b/cs-fundamentals/bash-reference-example.md index bfd4cdf..1a332ee 100644 --- a/cs-fundamentals/bash-reference-example.md +++ b/cs-fundamentals/bash-reference-example.md @@ -1,95 +1,15 @@ # Bash Reference -Sample reference of Bash Commands<br> -(Updated Feb 2024) ## Navigation - `pwd` - print work directory. - `ls` - list files in current directory. - `ls -l` - all files. - `ls -t` - sort files by time. - - `ls -a` - all files. - - `ls -F -l` OR `ls -Fl` - no need to have the extra space. - - `ls -r` - sort files by reverse order (recent at bottom). -- `cd` - change directory. - - Example: `cd data-shell`. - - `cd ..` - go back to one directory. - - `cd ../../` - go to root node. - - `cd ~` - back to home. - - `cd -` - back to last one. - - `cd {TAB}` - complete the next. -- `exit` = exit your shell (in the system). -## File Manipulation -- `mkdir [name]` make directory with name. -- `cp` - copy a file. - - Example: `cp original.txt duplicate.txt` -- `scp` - copy a file between two different machines over SSH. - - `scp [file name] [username@cluster.earlham.edu]` - copy to cluster from local computer. - - `scp [username@cluster.earlham.edu]:[filename]` - copy from cluster to working directory on local. -- `mv` - move file to new location, or rename. - - `mv draft.txt quotes.txt` renames the file. - - `mv draft.txt my_folder/` moves the file to my_folder/. -- `rmdir` - remove directory - - To remove a directory that is not empty: `rm -R -f [DIRECTORY]`. -- `rm` - remove file. - -# Reading files -- `cat` - concatenate, prints into the shell. - - `cat first.dat second.dat` (concatenates first and second). -- `wc` - word count. - - `wc -l` - counts lines in a file. -- `nano filename.txt` - edit text file in the shell interface. -- `grep` - search for text. - - Example: `cat myfile.txt | grep "hello"` searches myfile.txt for the string "hello". -- `head filename.txt` - show beginning of the file. -- `tail filename.txt` - show ending of the file. - -## Modules (available on cluster.earlham.edu) -- `module avail` - lists all the pieces of software set up with module -- `module list` - currently loaded modulefiles -- `module load [program name]` - loads the required module - -## Documentation/Helpful -- `man [command]` - get help for command - - use Q to quit -- `history` - show recent commands -- UP ARROW KEY - previous command - -## FOR Loops -``` -for size in 100 200 300 400 500 600 700 800; - do ./my_program $size; -done; -``` -This for loop will run `my_program` eight times, each with a different "size" arguement. - -## Bash Scripts - -``` -#! /bin/bash (It creates the ability of a file to become executable) -{Bash commands here} -``` - -chmod = change file modes or accecss control -chmod u+x script.sh -U = The user permission bits in the original mode of the file. -X = The execute/search bits. -777 = all user, all computers read and write. (absolute permissions) [chmod 777 script.sh] -Bash ./script.sh = grant permission without chmod - -The file .txt needs to be renamed to .sh -.sh = (file extension shell) -./script.sh (run the executable file script.sh) - -(To set up keys so you don’t have to enter password to switch between cluster servers) = ssh-keygen -b 2048 (Press enter without inputting anything to set everything to default) -ssh-copy-id [username]@bronte (Enter your cluster password) -Test → ssh whedon (to check if you need password to switch servers) - -rm -rf dirname = remove everything including all subdirectories and the directory itself -Cut head -1 -mv oldname newname (renaming file) -From shell command line: Qsub < [filename.qsub] (to run a qsub file) +## More sections... +- more commands... + - more options... -- GitLab