---+ Unix Commands Quick Reference Useful commands and flags that we get tired of looking up... ---++ Alphabetical Reference %CODE{bash}% cat yourfile.txt %ENDCODE% Prints the contents of the given file to the console. %CODE{bash}% cd put/target/directory/here %ENDCODE% Changes the working directory to whatever path is typed after cd. Without an additional argument, cd brings one back to the home directory. %CODE{bash}% du -hc %ENDCODE% Get a human-readable output of disk space usage. If you add =*= then it will give you this for all files in the current directory. %CODE{bash}% fgrep "words" yourfile.txt %ENDCODE% Print only lines in a file containing the given "words" in a particular file. %CODE{bash}% find word* %ENDCODE% Locates and gives file names of all files in the working directory containing word in the beginning of the file name. The * represents a wildcard so it can be placed before, after, or both in order to find files that contain the given query in a particular part of the file name.<p> %CODE{bash}% kill process %ENDCODE% Ends a particular process. Note that you can type =killall= to end multiple processes that match the name that is input. %CODE{bash}% ls %ENDCODE% Lists the contents of the working directory. Add =-a= to include invisible files. Add =-l= to show more information about each file such as its owner and permission flags. %CODE{bash}% mkdir directoryname %ENDCODE% Makes a directory with a name specified by the user. %CODE{bash}% nl yourfile.txt %ENDCODE% Numbers all the lines of a file. %CODE{bash}% ps %ENDCODE% Lists all process currently running. %CODE{bash}% pwd %ENDCODE% Prints the working directory path to the console. %CODE{bash}% rm yourfile.txt %ENDCODE% Deletes a given file. %CODE{bash}% rmdir yourdirectory %ENDCODE% Deletes a given directory. %CODE{bash}% source yourfile %ENDCODE% Reads and executes commands from the given file in the current environment. %CODE{bash}% which yourprogram %ENDCODE% Prints the the full path of the program to the console (note that its directory must be in your =$PATH=). Adding an =-a= after which prints all instances of the program.<p> ---++ Fixing Line Endings If you get odd errors after transferring a text file from a PC or Mac to a Unix machine, it's likely that you have a problem with [[http://en.wikipedia.org/wiki/Newline][newline characters]]. This is especially common when editing files in Excel and saving them to tab-delimited or comma-delimited files for input into. You can generally avoid this problem and fix the line endings by using an industrial strength text editor. This command converts Mac line endings in a saved Excel file to Unix line endings. %CODE{bash}% tr "\r" "\n" < input.tab >.converted.tab %ENDCODE% ---++ Merging commands to be serial on TACC Sometimes you have 96 short jobs that you want to run serially 8 at a time on 12 cores rather than requesting 96 cores. This command will combine every 8 lines in a file into one line separated by && so that these commands are now run on one core. %CODE{bash}% paste -s -d'#######\n' commands | sed "s/#/ \&\& /g" > commands8 %ENDCODE% ---++ Adding your path to the command prompt Add to your =.bashrc=, =.zshrc=, or similar shell startup script: %CODE{bash}% export PS1='\w\$ ' %ENDCODE% Now your current working directory will show up as part of your prompt. This can save you a lot of time typing =ls=.
E
dit
|
A
ttach
|
Watch
|
P
rint version
|
H
istory
: r8
<
r7
<
r6
<
r5
<
r4
|
B
acklinks
|
V
iew topic
|
M
ore topic actions
Barrick Lab
>
ComputationList
>
ProtocolsUnixCommandsQuickReference
Contributors to this topic
JeffreyBarrick, LucyLeblanc
Topic revision: r8 - 2024-07-09 - 22:32:58 - Main.JeffreyBarrick
Barrick Lab
Contact
Research
Publications
Team
Protocols
Reference
Software
UT Austin
Mol Biosciences
ILS
Microbiology
EEB
CSSB
CBRS
The LTEE
iGEM team
SynBioCyc
SynBio course
NGS course
BEACON
Search
Log in
Copyright ©2025 Barrick Lab contributing authors. Ideas, requests, problems?
Send feedback