Shell = '$'
Output = '>'
## Print Working Directory
$ pwd
## Change Directory: to /directory
$ cd /directory
# Examples:
>/directory
# Change Directory, from: /directory to /
$ cd ..
>/
# Change Directory: previous directory
$ cd -
# Change Directory: go to home
$ cd
# Or
$ cd ~
>~
## Display output one screen at a time
$ less file
$ more file
## Concatenate and print (display) the content of file(s)
$ cat file1
# Or
$ cat file1 file2
# Examples:
$ cat File1.txt File2.txt > union.txt
$ sort -u File1.txt File2.txt > unique_union.txt
# Put the contents of a file into a variable
$ my_variable=`cat File3.txt`
## Create a test file
$ echo "test" > test.txt
## Filename and Directory Completion
$ cd /opt/I[TAB]
> cd /opt/IBM
$ cd /opt/IBM[TAB][TAB]
>IBM/ IBMinvscout/
## List of Variablenames
$ $[TAB][TAB]
## Variablename Completion
$B[TAB]
>$BASH
## Print variable's value
$ echo $BASH_VERSION
> 4.2.45(1)-release
## Username's list
$ cd ~[TAB][TAB]
## Hostname's list
$ ssh @[TAB][TAB]
## Run a command script in the current shell
$ ./download-logs.sh
## Search the user's $path for a program file
$ which ssh
>/usr/bin/ssh
## Copy one or more files to another location
$ cp f1 f2
## Move or rename files or directories
$ mv old_name new_name
## TAR + GZIP
$ tar -czvf archive.tgz files/
## Create a symbolic link to a file or a directory
$ ln -s [OriginalSourceFile] [NewLinkFile]
## Change access permissions
# http://ss64.com/bash/chmod.html
$ chmod access file
# Examples:
$ chmod u+x script.sh
$ chmod a-x file
$ chmod go+rw file
# Read by owner
$ chmod 400 file
# Allow everyone to read, write, and execute file
$ chmod 777 file
## Change file owner and group
$ chown [user] [filename]
# Examples:
# Owner => root
$ chown root file
# Group => admin
$ chown :admin file
# Owner => root AND Group => admin
$ chown root:admin file
## Change group ownership
$ chgrp [group] [filename]
# Examples:
$ chgrp oracle /usr/database
## Change file timestamps
$ touch filename
# Exemples:
$ touch -d "2 hours ago" filename
$ find DIRECTORY -exec touch -d "2 hours ago" {} +
$ find /opt/phantomjs/tomcat/apache-tomcat-6.0.37/logs/ -type f -mtime +30 -exec rm -f {} \;
## Find a specific file
$ find . -type f -name log4j*
# Examples:
# Fin a file and change the modification date
$ find DIRECTORY -exec touch -d "2 hours ago" {} +
## Reload shell configurations
$ source ~/.profile
# Or
$ source ~/.bashrc
## Exceute last command starting by 'command'
$ !command
## Remote connection with SSH
$ ssh user@hostname
>password
## Copy a remote file
# Push:
$ scp location user@othermachine.com:destination
# Pull:
$ scp user@othermachine.com:location destination
# The '-r' parameter is used to copy an entire directory, or you may use * to match on multiple files/directories.
## Find a command from the history
$ history | grep command
## Maven
$ mvn clean package
## SVN
#Checkout
$ svn co https://sasvnd1.int.videotron.com/svn/...
# Update
$ svn up
## Delete a file
$ rm file
# Delete many files starting with the letter f
$ rm f*
# Delete a directory
$ rm -r directory
## Debug Apache/IHS configurations
httpd.exe -e debug -k start
# Restart Apache/IHS with new configurations
$ httpd.exe -k restart
## head & tail
# Print the first lines of a file (default: 10 lines)
$ head -100 file.log
# Print the last lines of a file (default: 10 lines)
$ tail -100 file.log
# Extract lines 40-50 from a file, first using head to get the first 50 lines then tail to get the last 10:
$ head -50 file.log | tail -10
## Load bash as default shell
$ vi .profile
# Add:
bash
## Add an alias in the bash
$ vi ~/.bashrc
# Add
alias ALIAS_NAME='command'
# Examples:
alias ll='ls -l'
alias tailf="tail -f SystemOut.log"
## Customize the shell prompt
$ export PS1="\n\u@\h \w\n$ "
# http://www.cyberciti.biz/tips/howto-linux-unix-bash-shell-setup-prompt.html
## Execute many commands in an "atomic" way
$ command1;command2
# Examples:
$ alias logs="cd /opt/IBM/WebSphere/AppServer/profiles/AppSrv01/logs;ls"
$ rm app; ln -s app_AAAAMMDD app
## Configure a "daemon"
$ crontab crontab_file
# Print the current crontab
crontab -l
# To debug the daemon, we need the mail because the deamon will tell us if a task had a problem
## Open a file in edit mode (or create it with a ':wq' at the end)
vi file
## Create a shell script
$ echo "#!/bin/bash" > script.sh
$ vi script.sh
$ chmod u+x script.sh
## Process viewer
$ top
# Or
$ ps
# Examples:
$ ps -ef | grep tomcat
See also:
http://ss64.com/bash/