Main Page
 The gatekeeper of reality is
 quantified imagination.

Stay notified when site changes by adding your email address:

Your Email:

Bookmark and Share
Email Notification
Project Cheatsheet
The purpose of this page is to illustrate a variety of useful commands along with usage (may vary depending on linux-flavor).

Command: cat filename.txt
Meaning: Show the content of a file (not too helpful if it is a big file). Using "less" is preferred nowadays.

Command: cd
Meaning: Allows you go move around the filesystem such as cd .. which goes back one directory or cd / which goes to the main directory.

Command: cp -arv /folderA /other/folderA
Meaning: This copies all files and folders in /folderA over to folderA in the /other folder. NOTE: /other/folderA does not already need to exist (it will be automatically created).

Command: chown webservices
Meaning: "chown" assigns the user "webservices" as the owner of the file "".

Command: chmod a+x
Meaning: "chmod" assigns permissions "a+x" to the file "". You should be able to use 600, 644, 755, 666 in place of "a+x".

Command: date
Meaning: Gets the current date and time on the server.

Command: date +%m-%d-%Y_%H:%M:%S
Meaning: Shows the current date and time as 01-20-2013_05:03:14.

Command: df -h
Meaning: show what is getting consumed on the hard drive.

Command: env
Meaning: Shows environment variables set for the current user. Handy if writing scripts on the server such as cron jobs.

Command: find . -name filename*
Meaning: Conduct a search to find filename with any text after the name (*) starting at the current location of period.

Command: grep -H -r "" /folder/
Meaning: Search for text inside of files. -r specifies to look in all sub-folders of "/folder/". -H will just return the filenames where matches are found instead of information on where the match is at in files.

Command: history
Meaning: Shows a recent history of the commands entered at the prompt for the user you are currently logged in with.

Command: ifconfig
Meaning: Show configured interfaces (in some circles may be referred to as nic cards) on the server.

Command: ifconfig eth0 | grep 'inet addr:'
Meaning: Get the IP address assigned to the interface (in some circles may be referred to as the nic card) eth0.

Command: kill -9 12345
Meaning: This varies by linux-flavor. 12345 is the PID (process ID) of the process you want to terminate. -9 requests immediate termination. Usually -15 is used first (if the process accepts it) to allow a graceful termination of the process to minimize any data loss.

Command: less filename.txt
Meaning: Shows the content of a file in steps with the spacebar (so you can scroll through file). When at the end of the file you can press the button "q" to return to the prompt.

Command: ls -a
Meaning: See hidden files and folders. ls -l will show you permissions assigned to files and folders, owners and a few other bits of information.

Command: mkdir /content/websites
Meaning: Create a folder "websites" inside the folder "content". Don't forget to set permissions / ownership information if needed.

Command: ps -C java f
Meaning: Show all running processes that are "java".

Command: ps aux
Meaning: This command shows all the processes that are running including resource consumption, how they were invoked and stat information. If a process shows a "D" for its STAT, that process is in a state of infinite sleep and is usually a disk / IO process and may also be an indicator of an issue with a disk. A process with a "D" stat cannot be issued interrupt signals unlike other STAT values. If the process needs to be killed, use the PID (such as 1234) and from the prompt enter kill -9 1234.

Command: ps -e -o pid,vsz,comm= | sort -n -k 2
Meaning: This command shows what is consuming RAM (vsz) on a server.

Command: rm -f somefile.txt
Meaning: Deletes a file.

Command: rm -r somefolder
Meaning: Deletes a folder and its contents.

Command: run-parts /etc/cron.d
Meaning: If you are putting together a cron script, for testing you can place it in /etc/cron.d and use the command to invoke cron to run it. However, you will want to ensure that there are not other scripts in that directory as they could be invoked as well.

Command: scp acctName@serverA:/folder/file.txt /myfolder
Meaning: This command (assuming you have SSH'ed to serverB where "/myfolder" is at) will copy the file from serverA to "/myfolder" on serverB. "acctName" is the account on serverA that you can SSH and login with. After you have entered the command you will be prompted for the password for "acctName" on serverA. If this activity has never been initiated between two servers you may be prompted (on serverB) to accept / save a key.

Command: su
Meaning: Allows you to switch your identity. For example, when you first access a server via SSH you should be a non-root user such as "admin" with the prompt being a $ (dollar sign). If you enter su root and the correct password your prompt will change to a # (pound sign).

Command: su webservices ./
Meaning: Start "" under the user "webservices" so it will stay running after you exit out of SSH. You'll need the password of the user if you are not already logged in as that user.

Command: sudoedit filename.txt
Meaning: Not always available (may have to use vi filename.txt) but when it is, will allow you to edit a read-only file assuming you are currently the root user. Other useful, text-oriented tips include:
  • When you want to insert text you need to press i
  • When you need to insert a new line press o (on the new line you can type text)
  • Press D (or lowercase d) to delete the entire line of text your cursor is on; dd to delete the current line
  • Press x (lowercase) to delete a character to the right of the cursor
  • Press X (uppercase) to delete a character to the left of the cursor
  • To delete blank lines in the file press ESC key (so you go to the : prompt) then enter :g/^$/ d and press enter
  • Press the ESC key when you are done editing or adding (so you go to the : prompt)
  • Press x (lowercase) to save the file with the changes. NOTE: You may need to enter x! to save a read-only file. Entering ZZ is an alernative to x
  • To close the text editor while you are at the : prompt (vi or sudoedit), enter q
NOTE: If available, since we're in the modern era now, you may opt to edit files using a GUI such as gedit assuming the server is setup for it.

Command: tail -f /usr/local/apache2/logs/error_log
Meaning: When logs are too big to open or copy, usually from a sloppy setup (although there can be many reasons for having out of control logs files size-wise), you should be able to enter the command to see the end of the file and then any new data added to it. You will need to CNTRL+z to stop the activity and get back to the prompt. If you would like to only see data coming into the log, you can add | grep "192\.168\.206\.1 " which would only show entries with the IP address specified.

Command: tail -f /usr/local/apache2/logs/error_log | grep -v -E '(on line 20)'
Meaning: Uses grep to only show lines that do NOT have "on line 20" in them.

Command: tail -f screenlog.0 | grep -v -E '(at org.restlet|at sun.reflect|at java.lang|at java.util)'
Meaning: Similiar to the previous command but for omitting multiple matches.

Command: tail -f screenlog.0 | grep -E '(allow only|CommunicationsException|last packet|Response took)
Meaning: This use of grep only will show lines which have one of the OR'ed text blocks.

Command: tail -f screenlog.0 | grep --line-buffered -v -E '(at org.restlet|at sun.reflect|at java.lang|at java.util)' > mymatches.txt
Meaning: This use of grep will only save lines to a file (mymatches.txt) which do NOT have any of the OR'ed text blocks.

Command: top
Meaning: From the prompt this shows the running processes and resource consumption stats of the hardware and running processes.

Command: touch newfile.txt
Meaning: Creates a new file "newfile.txt" at your current directory location, if it does not already exist.

Command: uname -a
Meaning: Get basic server information.

Command: watch -n 10 'echo "show processlist" | mysql -u login -p password | grep -v "show processlist"'
Meaning: For the snoop command to work, the snp module may need to be installed on the server, or, may need to run as root. The command runs until you've CNTL + z or CNTL + c. -n is number of seconds to wait before running again.

About Joe