Basic Linux Command for Beginners

The purpose of this document is to understand the Basic Linux command in a fast or simple way. It assumes that we have very little exposure of Linux command.

If we are familiar with DOS command then it is easy to understand Linux command with the following differences:

  1. In Linux/UNIX, commands and filenames are case sensitive, meaning that typing “EXIT” instead of the proper “exit” is a mistake.
  2. In DOS, the forward-slash “/” is the command argument delimiter, while the backslash “\” is a directory separator. In Linux/UNIX, the “/” is the directory separator, and the “\” is an escape character.
  3. The DOS world uses the “eight dot three” filename convention, meaning that all files followed a format that allowed up to 8 characters in the filename, followed by a period (“dot”), followed by an option extension, up to 3 characters long (e.g. FILENAME.TXT). In UNIX/Linux, there is no such thing as a file extension. Periods can be placed at any part of the filename, and “extensions” may be interpreted differently by all programs, or not at all.

cat

Display the contents of a text file on the screen. For example: cat contact.txt would display the file we created in the previous section.

tail -f

Display the last few lines of a text file, and then output appended data as the file grows (very useful for following log files!). Example: tail -f /var/log/messages

top

Displays CPU processes in a full-screen GUI. A great way to see the activity on your computer in real-time. Type “Q” to quit.

echo

Display text on the screen. Mostly useful when writing shell scripts. For example: echo “Hello World”

find

It can be used to search for files matching certain patterns, as well as many other types of searches. example: find . -name \*mp3. This example starts searching in the current directory “.” and all subdirectories, looking for files with “mp3” at the end of their names.

locate

A quick way to search for files anywhere on the file system. For example, you can find all files and directories that contain the name “oracle” by typing: locate oracle

which

Shows the full path of shell commands found in your path. For example, if you want to know exactly where the “grep” command is located on the filesystem, you can type “which grep”. The output should be something like: /bin/grep

cp, mv

First one Copies a file from one location to another. Example: cp mp3files.txt /tmp (copies the mp3files.txt file to the /tmp directory) and second one moves a file to a new location, or renames it. Example: mv mp3files.txt /tmp (copy the file to /tmp, and delete it from the original location)

rm

Delete a file. Example: rm /tmp/mp3files.txt

mkdir, rmdir

First one Make Directory. Example: mkdir /tmp/myfiles/ and second one Remove Directory. Example: rmdir /tmp/myfiles/

ls

List all files in the current directory, in column format For example: ls /usr/bin/d* This command list all files whose names begin with the letter “d” in the /usr/bin directory.

cat /proc/cpuinfo, cat /proc/meminfo

Display information about CPU and Memory usage

uname -a

Prints system information to the screen (kernel version, machine type, etc.)

ps

Lists currently running process (programs).

more, less

First command Display a file, or program output one page at a time and second one is the improved replacement of first one allows you to move backward as well as forward. Example: ls -la | more

grep

Search for a pattern in a file or program output. For example, to find out which TCP network port is used by the “nfs” service, you can do this: grep .nfs. /etc/services. This looks for any line that contains the string “nfs” in the file “/etc/services” and displays only those lines.

su

It allows you to switch to another user account temporarily. Example: su Shahid, su – (Switch to root, and log in with root’s environment)

“history”

It shows your complete command history.

chmod

To change file access permission.

Note: Press (CTRL-R) and then type any portion of a recent command. It will search the commands for you, and once you find the command you want, just press ENTER.

Help: When you are struck and needing help with a Linux command just press “-h” or “help”

Example:  grep  — help (built in help)

Example: man ls (get the help on ls) or man man (a manual about how to use the manual)

Example: info df (load information page)

For more frequently used OS Command for DBA click on the link: Frequently used OS (Linux/Solaris/AIX) Command for DBA

Advertisements
Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: