Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Expand
titleTable of Contents

Table of Contents


...


External References


...

 Writing scripts for cd
Code Block
languagenone
titleedit .bashrc
alias cdr="cd /cul/web/elr37-dev.library.cornell.edu/htdocs/rails/;pwd"

...

Code Block
languagenone
titleedit .bash_profile
if [ -f ~/.bashrc ]; then
  source ~/.bashrc
fi


...

Updating $PATH
Code Block
languagenone
# 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
languagenone
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

sudo

sudo mkdir test

run command as root


sudo -s


open a root shell


sudo -s -u user

sudo -s -u net33

open a shell as user


type cmdname


shows you the type of a command which is the executable location for programs


whereis filename

whereis mysql

shows location of all files with that name


whoami

whoami

shows the currently logged in user


scp -r localfilename remoteuser:remotedir

scp -r elr37@remote-host:/path/to/directory /local/path/to/where/you/want/to/put/it

scp -r elr37@elr37-dev.library.cornell.edu://cul/web/elr37-dev.library.cornell.edu/htdocs/rails/questioning_authority ~/questioning_authority_LD_BRANCH

secure copy from local to remote machine

NOTE: -r is only needed for recursive copy of an entire directory

echo $SHELL

echo $SHELL

show which shell is running


grep -r pattern path

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 pattern path | wc -l
grep "<record>" bib.xml | wc -1Count 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

/etc/inid.d/service_name start

ex. sudo /etc/init.d/tomcat-sf-lib-app-018.serverfarm.cornell.edu start

stop

/etc/inid.d/service_name stop


restart

/etc/inid.d/service_name restart


status

/etc/inid.d/service_name status


...

ActionCommandComments
startsudo service service_name startex. sudo service mysqld start
stopsudo service service_name stop
restartsudo service service_name restart
statussudo service service_name status


...

Find Command

(reference)

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
languagenone
$ 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
languagenone
brew install tree


...

Create all directories on a path
Code Block
languagenone
# 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
languagenone
$ jobs
[1]+  Stopped                 vi test
$ fg 1

...

Ref: how-can-i-resume-a-stopped-job-in-linux


...

Code Block
languagenone
ln -s {real-filename} {symbolic-filename}


...

Compressing and Extracting tar.gz and zip files
Code Block
languagenone
# 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
languagenone
diff -bur folder1/ folder2/


...

tail
Code Block
languagenone
# 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
languagenone
# 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
languagenone
$ 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.

...