Main /
BasicBashCommands
Definitions
- Directory: Your current location within the computer. Similar to a "folder."
- Bash shell or Shell: The shell is the middle man between you and the computer. It takes your commands and relays them to the computer in computer language.
Tips and Tricks
ctrl + c
Cancel a running process- The tab button will autocomplete your command/reference, else it will autocomplete until two or more possible entries are possible.
- Example: Lets say your have the following file names in a certain directory:
slurm-11283945 slurm-11283487 slurm-12990009- Typing: "
$ s
" + tab
autocompletes to slurm-1 - Typing: "
$ slurm-12
" + tab
autocompletes to slurm-12990009
- Typing: "
- Example: Lets say your have the following file names in a certain directory:
- Pressing the "up" arrow will cycle through your previous bash commands.
- Knotts group computers: @ComputerName.et.byu.edu
- Note if you are working remotely you will need to login into the engineering network before you can connect to Watt or any of the group computers.
$ exit
Exits the ssh client or any other program you are working in. Directory is placed where it was originally located before the ssh or program was executed.$ cd FlderName
Change Directory; Moves the working directory into the folder/directory indicated.$ ls
List; Lists the contents of the working directory$ pwd
Print working directory. Prints to the screen your current directory and filepath. Useful when moving or copying files/folders to different locations or computers.$ vim FileName
VIM editor; Used to edit files, text or code. There are lots of commands and things you can do in this mode, but we won't go over vim editor commands on this page.$ rm FileName
* *
Wildcard; pretty much an "apply to all" reference.$ ls *.txt
This will list everything that ends in .txt within the working directory.$ rm slurm*
This will permanently remove everything that starts with "slurm." Be careful when deleting stuff with "*" in the reference.
- To run a command in the background use "&" A process ID will be generated.
$ ./SomeProgram.exe &
$ jobs
Use this command to see all background processes.$ kill PIDnumber
Kills the background process with that specific process ID number.$ man SomeBashCommand
Generates a manual detailing the uses and flags associated with that bash command.
Basic Commands
$ ssh UserName@ServerName
SSH client login; A remote login program typically used to access Watt, the supercomputer or other computers in our group. If a password is set-up you will be prompted to input it before access is granted.- example:
$ ssh Username@ssh.fsl.byu.edu
- Some commonly used server paths:
- Supercomputer: @ssh.fsl.byu.edu
- Watt: @watt.et.byu.edu
- Engineering network (CAEDM): @ssh.et.byu.edu
- Knotts group computers: @ComputerName.et.byu.edu
- Note if you are working remotely you will need to login into the engineering network before you can connect to Watt or any of the group computers.
- example:
$ exit
Exits the ssh client or any other program you are working in. Directory is placed where it was originally located before the ssh or program was executed.$ cd FlderName
Change Directory; Moves the working directory into the folder/directory indicated.$ ls
List; Lists the contents of the working directory$ pwd
Print working directory. Prints to the screen your current directory and filepath. Useful when moving or copying files/folders to different locations or computers.$ vim FileName
VIM editor; Used to edit files, text or code. There are lots of commands and things you can do in this mode, but we won't go over vim editor commands on this page.$ rm FileName
Remove; Permanently deletes the given file. No way to recover accidentally deleted files. Use with caution. Multiple entries deletes all files specified.- -r The folder flag. Use this flag if you want to remove a folder and its contents, remember you permanently delete everything. Use with extreme caution.
./
or../
or~/
Points the the current, one previous, or home directory, respectively. Not a command itself but a reference.$ cd ../
Moves you to the one previous directory$ ./SomeProgram.exe
Executes the SomeProgram.exe executable and runs the code within your current directory.
$ mv FileFromHere FileToHere
Move
command; Moves and/or renames files- Renaming:
$ mv OldName.txt ./NewName.txt
- Moving:
$ mv TheText.txt ~/home/cosmo/compute/
- Move & rename:
$ mv OldName.txt ~/home/cosmo/compute/NewName.txt
- Note you can move entire folders
- Note this command will overwrite pre-existing files or folders if the names are the same. Use caution.
- Renaming:
$ cp OriginalFile FileToHere
Copy
and paste command; copies data from one location and moves it to another; the original file is untouched. Same set-up and capabilities as mv only the original is not deleted when using cp. It is recommended you be in the destination folder when you perform the command. Only the last entry is the destination, multiple entries indicate multiple things to copy to the one destination You can rename the file to be copied by putting it at the end of the destination.$ cp ~/compute/Folder1/Folder2/TheFile ./NewFileName
- To not rename just leave the destination reference and you will retain the original name. aka just leave the last section to read:
./
- To not rename just leave the destination reference and you will retain the original name. aka just leave the last section to read:
$ cp TheFile1 ~/compute/Folder1/TheFile2 TheFile3 ./Folder/Destination/
- -r This is the folder flag, indicates that you will be copying an entire folder and its contents at some point in the copy.
$ scp OrigionalFile username@ServerName:~/FileToHere
Secure copy and Paste command; File Transfer. Same flags and function as thecp
command, but transfers files securely. Use this command when transferring files between computers. The server can be the copied or pasted source.$ scp username@ssh.fsl.byu.edu:~/compute/Folder1/TheFile.txt ./
$ pscp ./TheFile username@watt.et.byu.edu:~/FilePath/
- Use pscp if you are on a Windows 10 machine. You may need to download and install pscp first.
- A windows machine can also use PuTTY. A link to download PuTTY is here. I recommend the putty.zip download as it has all the files bundled together and comes with an installer.
- -r flag can also be used with this command to securely copy entire folders.
$ mkdir FolderName
Make directory or make folder; This makes a new folder or a new directory.$ sbatch SchedulerCommands
Submit batch; This is the command you use to submit a job, batch of jobs, or submission script to the supercomputer scheduler. Written in Bash language and scheduler commands.- Example: @@$ sbatch SubmissionScript.sbatch
- Example:
$ sbatch –N1 –n1 –-mem- per-cpu=100M –t00:05:00 –-qos=test JobName.sh
$ squeue -u UserName
View jobs in queue, the -u tag indicates you want to only view a specific user in the queue.$ scancel JobNumber
Cancel job; cancels the specified job if the job is running or in the queue. Will take multiple job numbers in one command.$ scancel 1824744 1928734
$ sh ShelScript.sh
Run shell script; use this command to run a shell script in your directory. Shell scripts are typically denoted with an .sh extension. User inputs are indicated in the spaces after the script file.- Example:
$ sh ShellScript.sh Input1 Input2
- Example:
$ module [command]
There are multiple module commands. The following contains common module commands. Programs that require you to load a module before execution include: matlab, python, valgrind. Using a module to execute a script is also listed.$ module avail
Shows a list of all available modules on your system.$ module list
Lists all currently loaded modules on your system.$ module purge
Clears all loaded modules on your shell. The shell will reset to default when the shell is closed.$ module load ModuleName
Loads the indicated module onto your shell
The following are examples of executing a script with a loaded module on your shell. Syntax displayed is interchangeable.
$ python < ThePythonScript.py
$ matlab TheMatlabScript.m
$ gzip FileName.txt
Zip command; zips a file into a compressed file and will automatically add the .gz extension.- bzip2 is another zipping command. It executes slower but produces smaller files.
$ gunzip FileName.txt.gz
Unzip command; unzips the indicated file. The file must have been zipped using the gzip command and not some other zipping command. (like bzip)- bunzip2 unzips a file that was zipped using bzip2
$ tar zcvf TarBallName.tar.gz FileName1 FileName2
etc.
Create gzip tarball; compresses and tar all the files indicated at the same time. Note your FileNames can be file paths to different files$ tar zxvf TarBallName.tar.gz
uncompress
the tarball in one step- For anything bzip2 (.bz2) use a "j" instead of a "z"
$ chmod [command] FileName
Change Mode; this changes the permissions on a file. The[command]
can consists of a triplet number code or individual user(u)
, group(g)
, or other(o)
specification.$ chmod 764 FileName.exe
The triplet number code references user/group/other where read-only=4, write-only=2, and execute-only=1. The sum of all options desired equal the reference's permission (so a permission of 6=read and write)$ chmod g=rx FileName.exe
Only the specified reference is changed in this example. The code r=read-only, w=write-only and x=execute-only are used to define permission. In this example the group can read and execute.