• Topic ID: concept_fnl_rsf_v3b
  • Version: 2.0
  • Date: Oct 28, 2019 4:25:06 AM

Linux Commands

1 Linux Commands

1.1 Essentials

logout

Use this command when you are done, always.

/

Root directory.

./

Current directory.

./command_name

Run a command in the current directory when the current directory is not on the path.

../

Parent directory.

~

Home directory.

1.2 Files and Directories

cd

Change directory.

pwd

Print working directory - the directory where you are.

mkdir

Make a new directory.

ls

List files.

ls -a

Lists all files in the directory, including hidden files. A hidden file is one whose name starts with a period (.).

cp

Copy a file.

less

View a text file.

cat

Prints the contents of a file on the screen.

more

Display the contents of a file, pausing between each screen full. Type more file.

control-D

Pressing the control key and the d key at the same time interrupts programs and returns you to the prompt.

1.3 System Status

date

Displays the current date and time.

top

A program to see how your memory and CPU are holding up.

ps

Display running processes ('ps -ef | grep username' gives all the processes owned by a particular user).

w

Display who is on and where they are on from.

tail -f

Tail follow a file as it grows.

chkconfig -list

Query or update system services/daemons for different run levels.

df

Displays capacity and free capacity on different physical devices such as hard drive partitions that are mounted on the file system. Gives free space in blocks.

du

Displays information on disk usage.

du / -bh | less

Display detailed disk usage for each subdirectory starting at root.

1.4 Networking

telnet

Open a remote session with host.

rlogin

Open a remote session with host.

ftp

File Transfer Protocol: send and receive files between machines.

ping

Check to make sure a remote machine is reachable.

1.5 Editors and Text Processors

jmacs

Visual Editor.

grep

Searches a file for a pattern.

1.6 Mount/Unmount a USB Device at the Host Computer

1.6.1 Mount a USB Device

Notice Image
  • notice
  • USB device has to be formatted with FAT32 file system.
  1. Plug in the USB device to one of the USB ports on the front of the Host computer.

  2. Open a Terminal Window.

  3. Enter the following commands to become root:

    1. Type: su-

    2. Type: <root password>

  4. Type: mountUSB

  5. Exit root.

  6. Exit the Terminal Window.

1.6.2 Unmount a USB Device

  1. Open a Terminal Window (if not already open).

  2. Enter the following commands (if not already at root permission):

    1. Type: su-

    2. Type: <root password>

  3. Type: unmountUSB

  4. Exit root.

  5. Exit the Terminal Window.

2 Using Linux Commands

2.1 Navigation

2.1.1 cd

The cd command changes directories. It's a very common navigation command that you'll end up using, just like you might have done in MS-DOS.

You must put a space between cd and the ".." or else it won't work; Linux doesn't see the two dots as an extension to the cd command, but rather a different command altogether.

2.1.2 ls

The ls letters stand for list. It basically works the same way as the dir command in DOS. Only being a Unix command, you can do more with it.

Typing ls will give you a listing of all the files in the current directory. If you're new to Linux, chances are that the directories you are commonly in will be empty, and after the ls command is run, you aren't given any information and will just be returned to the command prompt (the shell).

There are “hidden” files in Linux, too. Their file names start with a dot, and doing a normal ls won't show them in a directory. Many configuration files start with a dot on their file names because they would only get in the way of users who would like to see more commonly used items. To view hidden files, use the -a flag with the ls command, i.e. ls -a.

To view more information about the files in a directory, use the -l flag with ls. It will show the file permissions as well as the file size, which are probably what are the most useful things to know about files.

You might occasionally want to have a listing of all the subdirectories, also. A simple -R flag will do, so you could look upon ls -R as a rough equivalent of the dir /s command in MS-DOS.

You can put flags together, so to view all the files in a directory, show their permissions/size, and view all the files that way through the subdirectories, you could type ls -laR.

2.1.3 pwd

This command simply shows what directory you're in at the moment. It stands for “Print Working Directory”. It's useful for scripting in case you might ever want to refer to your current directory.

2.2 Editing

The basic syntax to invoke these text editors is the same. Type the name of the editor followed by the file you want to edit, separated by a space in between. Non-existent files will be blank. Blank files will be blank as well.

vim

Most modern distributions include vim, derived from the infamously arcane Unix editor, vi.

Using vim is different in that there are several modes in which you use it. To do actual editing of the files, press ESCi (both separately). Then to save it, press ESC:w . Escape, the colon, and “w” should be keyed in one after the other. Finally, to quit, type ESC:q . The same rules apply as in previous vim commands.

You can use “w” and “q” at the same time to enable yourself to write to the file and then quit right afterwards. Just press ESC:wq .

If you don't have vim installed, try vi instead.

2.3 Monitoring Your System

2.3.1 tail

The program tail allows you to follow a file as it is growing. It is often used to follow /var/log/messages, by typing tail -f /var/log/messages. Of course, you can use anything else, including the other logs in /var/log/. Another file you may want to keep an eye out for is /var/log/secure.

If you want to leave that running all the time, it's recommended you have some sort of terminal program in X, logged in as root through su.

Another program you may want to look at is head. It monitors the top of the file specified, instead of the bottom.

2.3.2 top

This program shows a lot of stuff that goes on with your system. In the program, you can type:

M for memory usage information

P for CPU information

q to quit

2.3.3 w

Typing w will tell you who is logged in. This can be helpful if you're the only one who uses your computer and you see someone logged in that's not supposed to be.

Another alternative is who.

3 Linux Reference Books

  • Learning GNU Emacs - another book on another powerful text editor. It's good especially if you program or simply prefer Emacs.

  • Learning Red Hat Linux, 2nd Edition, by Bill McCarty (Paperback)

  • Sams Teach Yourself Linux Programming in 24 Hours (Complete Learning Edition), by Warren Gay (Editor), Tony Zhang (Editor)

  • Essential Reference for any Linux Newbie :-): A list by Jacob Weiskoff,

  • Red Hat Linux 7 for Dummies