---+ Unix Commands Quick Reference Useful commands and flags that we get tired of looking up... ---++ Disk Space The <code>du</code> command is verbose and confusing if you run it without options. Here is how to get a human-readable output and a grand total for the path argument (omit for current directory). <code>du -hc</code> ---++ 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>tr "\r" "\n" < input.tab >.converted.tab</code> ---++ 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>paste -s -d'#######\n' commands | sed "s/#/ \&\& /g" > commands8</code> ---++ Adding your path to the command prompt Add to your <code>.bashrc</code> or similar bash startup script: <code>export PS1='\w\$ '</code> ---++ Useful Bash Commands These commands are also compatible with the Terminal (Mac OS X) as well as the Windows Bash emulator called [[http://cmder.net/][Cmder]].<p> <code>cat yourfile.txt</code> <br>Prints the contents of the given file to the console.<p> <code>cd put/target/directory/here</code> <br>Changes the working directory to whatever path is typed after cd. Without an additional argument, cd brings one back to the home directory.<p> <code>fgrep "words" yourfile.txt</code> <br>Print only lines in a file containing the given "words" in a particular file.<p> <code>find word*</code> <br>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>kill process</code> <br>Ends a particular process. Note that you can type killall to end multiple processes that match the name that is input.<p> <code>ls</code> <br>Lists the contents of the working directory.<p> <code>mkdir directoryname</code> <br>Makes a directory with a name specified by the user.<p> <code>nl yourfile.txt</code><br>Numbers all the lines of a file.<p> <code>ps</code><br>Lists all process currently running.<p> <code>pwd</code> <br>Prints the working directory path to the console.<p> <code>rm yourfile.txt</code><br>Deletes a given file.<p> <code>rmdir yourdirectory</code><br>Deletes a given directory.<p> <code>source yourfile</code><br>Reads and executes commands from the given file in the current environment.<p> <code>which yourprogram</code><br>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> ---++ Adding Directories to the PATH Variable When you invoke commands such as <code>python3</code> via Bash, it searches all file directories listed in your PATH in order to execute that command. Errors such as "command not found" (Linux) or "not recognized as an internal or external command, operable program or batch file" (Windows) when you try to invoke something mean you need to add the directory containing that program to your PATH. <p> <code>echo %path%</code> shows everything in your PATH on Windows while <code>echo $PATH</code> does the same for Linux/Unix systems.<p> <code>PATH=$PATH:~/your/directory/here</code> and <code>PATH=~/your/directory/here:$PATH</code> add the given directory to the end or the beginning of your PATH variable list, since when you invoke a command, the directories will be searched from beginning to end and the first match will be what is invoked. This is for Linux/Unix.<p> The Windows equivalent on Cmder is <code>PATH=%PATH%;C:\your\directory\here</code>.
E
dit
|
A
ttach
|
Watch
|
P
rint version
|
H
istory
: r6
<
r5
<
r4
<
r3
<
r2
|
B
acklinks
|
V
iew topic
|
M
ore topic actions
Barrick Lab
>
ComputationList
>
ProtocolsUnixCommandsQuickReference
Contributors to this topic
JeffreyBarrick, LucyLeblanc
Topic revision: r6 - 2020-02-14 - 03:19:21 - Main.JeffreyBarrick
Barrick Lab
Contact
Research
Publications
Team
Protocols
Reference
Computation
Software
UT Austin
Mol Biosciences
ILS
Microbiology
EEB
CSSB
CBRS
The LTEE
iGEM team
SynBioCyc
SynBio course
NGS course
BEACON
Search
Log in
Copyright ©2024 Barrick Lab contributing authors. Ideas, requests, problems?
Send feedback