...
Expand | ||
---|---|---|
| ||
|
...
External References
- Linux/UNIX Command Ref
- Advanced commands (mostly ubuntu oriented)
- .bash_profile vs .bashrc by Josh Staiger
- A Unix/Linux “find” Command Tutorial by Wayne Pollock
- Show all running processes in linux by nixCraft
- Kill Process in Linux or Terminate a Process in UNIX / Linux Systems by nixCraft
...
Writing scripts for cd
Code Block | ||||
---|---|---|---|---|
| ||||
alias cdr="cd /cul/web/elr37-dev.library.cornell.edu/htdocs/rails/;pwd" |
...
Code Block | ||||
---|---|---|---|---|
| ||||
if [ -f ~/.bashrc ]; then source ~/.bashrc fi |
...
Updating $PATH
Code Block | ||
---|---|---|
| ||
# view PATH echo $PATH # update PATH PATH=$PATH\:/dir/path ; export PATH |
...
NOTE: cd scripts won't work correctly from bin. Need to add them as an alias in .bashrc. See notes under Writing scripts for cd.
...
Append a line to a text file
Code Block | ||
---|---|---|
| ||
echo "line to append" >> path/to/file echo "gem: --no-document" >> ~/.gemrc |
...
Check file's md5
CYGWIN
- md5sum FILE_NAME
Mac terminal
- openssl md5 FILE_NAME
...
sudo, type, whereis, whoami, scp, echo, grep
Command | Example | Action | Comments |
---|---|---|---|
|
| run command as root | |
| open a root shell | ||
|
| open a shell as user | |
| shows you the type of a command which is the executable location for programs | ||
|
| shows location of all files with that name | |
|
| shows the currently logged in user | |
scp -r elr37@remote-host:/path/to/directory /local/path/to/where/you/want/to/put/it |
| secure copy from local to remote machine | NOTE: -r is only needed for recursive copy of an entire directory |
|
| show which shell is running | |
| grep -r foo * | Starting at current directory, look for 'foo' in all files including subdirs. | NOTE: -r is only needed for recursive search through subdirs |
| grep "<record>" bib.xml | wc -1 | Count the number of matches for grep. | In the example, it will count the number of times that <record> appears in file bib.xml. |
...
Working with Services
Action | Command | Comments |
---|---|---|
start |
| ex. sudo /etc/init.d/tomcat-sf-lib-app-018.serverfarm.cornell.edu start |
stop |
| |
restart |
| |
status |
|
...
Action | Command | Comments |
---|---|---|
start | sudo service service_name start | ex. sudo service mysqld start |
stop | sudo service service_name stop | |
restart | sudo service service_name restart | |
status | sudo service service_name status |
...
Find Command
Code Block |
---|
find where-to-look criteria what-to-do # prints names of files that directly match foo (e.g. /usr/foo, /usr/bin/foo) find / -name foo # prints names of files that contain foo (e.g. /usr/myfoo, /usr/bin/foobar) find / -name foo # suppress permission denied statements find /. -name *foo* 2>/dev/null |
...
Tree command
Code Block | ||
---|---|---|
| ||
$ tree . ├── contrib │ ├── analysis-extras │ │ ├── README.txt │ │ ├── lib │ │ │ ├── icu4j-49.1.jar │ │ │ ├── morfologik-fsa-1.5.5.jar │ │ │ ├── morfologik-polish-1.5.5.jar │ │ │ └── morfologik-stemming-1.5.5.jar │ │ └── lucene-libs │ │ ├── lucene-analyzers-icu-4.3.0.jar │ │ ├── lucene-analyzers-morfologik-4.3.0.jar │ │ ├── lucene-analyzers-smartcn-4.3.0.jar │ │ └── lucene-analyzers-stempel-4.3.0.jar │ └── extraction │ └── lib └── solr-analysis-extras-4.3.0.jar |
...
Code Block | ||
---|---|---|
| ||
brew install tree |
...
Create all directories on a path
Code Block | ||
---|---|---|
| ||
# creates directories /my /my/path /my/path/here if they don't already exist mkdir -p /my/path/here/ |
...
pgrep, pidof, top, ps, kill
Reference: http://www.cyberciti.biz/faq/show-all-running-processes-in-linux/
...
You will have to use sudo if you didn't start the process.
...
Resuming a paused job after <ctrl><z>
Code Block | ||
---|---|---|
| ||
$ jobs [1]+ Stopped vi test $ fg 1 |
...
Ref: how-can-i-resume-a-stopped-job-in-linux
...
Symbolic Links
Code Block | ||
---|---|---|
| ||
ln -s {real-filename} {symbolic-filename} |
...
Compressing and Extracting tar.gz and zip files
Code Block | ||
---|---|---|
| ||
# extract to current directory tar -zxvf yourfile.tar.gz # extract to specified directory tar -C /myfolder -zxvf yourfile.tar.gz # zip file zip filename.zip file1 file2 file3 # zip directory zip -r filename.zip /myfolder # unzip unzip filename.zip |
...
recursive diff
Code Block | ||
---|---|---|
| ||
diff -bur folder1/ folder2/ |
...
tail
Code Block | ||
---|---|---|
| ||
# show last few lines and exit tail /path/to/file # show last few lines as they update tail -f /path/to/file # show last n lines as they update tail -n 60 -f /path/to/file |
...
du
Code Block | ||
---|---|---|
| ||
# how much space is used in the current directory recursively du -h . 2>/dev/null |
...
This will list all directories, but not subdirs. Totals will include space used by each directory + their subdirs.
...
Debugging full memory (RAM)
List processes that are using the most memory...
...
Code Block | ||
---|---|---|
| ||
$ free -m total used free shared buffers cached Mem: 16041 1298 14742 0 36 131 -/+ buffers/cache: 1130 14911 Swap: 0 0 0 |
Debugging full memory (disk space)
This will list all directories, but not subdirs. Totals will include space used by each directory + their subdirs.
...