Linux/GNU Quick Command List

The purpose of this page is to keep a good list of commands used in Linux/GNU.

Mount an .iso Image

Create a mount point for the .iso:

sudo mkdir /mnt/iso

Now mount the .iso in the mount point with the following command:

sudo mount myiso.iso /mnt/iso/ -o ro,loop=/dev/loop0 -t iso9660

Or the short version:

sudo mount myiso.iso /mnt/iso/ -o loop

And unmount it when you are finished:

sudo umount /mnt/iso

Create an iso

Creating an ISO image using mkisofs

If you need to generate your own ISO, mkisofs is a great tool for doing it. You don’t need fancy tools or GUI front ends to use it, either (though you may wish to employ your favorite graphical file manager). Just follow these simple steps:

  1. Create a temporary directory from which the ISO’s files will be read.
  2. Insert files into that directory and arrange them in the manner you would like them to appear in the ISO.
  3. From a directory outside of the tempoary ISO directory, run the following command:
mkisofs -f -R -r -l -J -Vvolid -Aappid -Ppubid -odest.iso src 
  • volid: is the volume ID to be written into the master block;
  • appid: describes the application contained within the ISO;
  • pubid: names the publisher of the ISO (CD-ROM), usually including adequate contact information, such as a phone number or email address;
  • dest.iso: is the destination filename of the newly created ISO image;
  • src: is the temporary ISO directory containing the files and file structure you wish to have included in the ISO image.
  1. These parameters are good defaults. You can customize them, however. For more information, see man mkisofs.

Cd Ripping and Burning from the Command Line

Nero .nrg archives

Nero is a popular program for Windows. CD images made with Nero use the filename.nrg format and similar to, but not the same as .iso images.

You need to convert Nero images to standard ISOs using the program Nrg2Iso in order to burn them as usual under Linux/GNU.

sudo apt-get install nrg2iso

To use nrg2iso type:

nrg2iso filename.nrg filename.iso

The Core Commands

ls

Description: ls is the functional equivalent of dir on DOS systems. ls give a basic file listing in the current directory.

Command Line: To use ls, you may just type ls at any command prompt. The argument -a tells ls to list all files, including hidden ones. The argument -l tells ls to give a long listing, one with file sizes, ownership information, and dates/times.

Examples:

$ls -al

This will list all files in the current directory, including all hidden files, and will list their file sizes, ownership, and date/time information.

cd

Description: cd allows you to change the directory you are currently in. cd is a very simple command.

Command Line: cd takes no other arguments besides the name of the directory you are changing to.

Examples:

$cd /usr/local/

This will change the current directory to /usr/local

pwd

Description: You know how to change directories, but can’t figure out what directory you’re in? pwd will give you the answer. pwd outputs the current directory.

Command Line: pwd takes no arguments.

Examples:

pwd

The output will look something like:

/usr/local/

less

Description: Installed on most Linux systems, less is a “pager” - it pauses the output of text at every page and allows scrolling through a text file. less is the functional equivalent of more, but has features not found in more. Remember: less is more.

Command Line: There are no significant command line arguments for less

Usage Once less has been run, and is pausing the output of text, you can scroll up and down using the arrow keys, use pageup and pagedown to scroll up and down by pages, and can press the spacebar to go down a page, and enter to go down one line.

Examples: less can be used in two ways. Firstly, it can directly read a text file, such as:

less document.txt

It can also have text piped to it, such as:

last | less

In this example, less allows “paging” of the output from last.

cp

Description: cp is a basic file copy utility. Just as in DOS, cp takes arguments that include the wildcards * and ?

Command Line: cp can be used in the following format: cp by default cp does not copy directories, but given the -R option, it will.

Examples: Copying multiple files:

#cp *.html /home/httpd/html/

this copies all .html files in the current directory to /home/httpd/html

$cp -R * ../backup/

copies all files and subdirectories to the directory backup which is on the same level as the current directory.

mv

Description: mv is a utility that functions both as a rename utility and a move utility. It can be used to move files and whole directory structures as well.

Command Line: mv, as cp, has few significant command line options besides the -b option, which makes a backup copy of the files being moved.

Examples: First, an example of moving files:

$mv misplaced* misc/

The example above moves all the files that match misplaced* (read about wildcards if you don’t understand what this means) from the current directory into the subdirectory misc Another example, this time, renaming a file:

$mv bad-filename good-filename

rm

Description: All operating systems must have a delete feature, and rm does exactly that for Linux. Of course, you must remember, that in Linux, you have much more freedom to do things, and having such freedom, you must also be more careful how you go about deleting things. I advise you to be cautious when deleting things as root, as recovering erased data is very difficult, and often with the power rm gives you, it also assumes you know what you are doing in many cases, and will not confirm your actions before it does them.

Command Line: The most useful command line parameters are -r and -f - and combined, they can be deadly. -r deletes directories along with all subdirectories and files contained within that directory. -f “forces” it, which means it forces the files to be removed and does not ask for a confirmation. This can be helpful if you want to delete a directory tree of 100 files that you don’t want to press ‘y’ for 100 times. These two can be combined as -rf.

Examples: Removing a single file is simple:

$rm oldfile.c

A group of files can be removed either of these ways:

$rm badfiles*
$rm badfile1 badfile2 badfile3

Removing a directory, without confirmation, can be done as follows:

$rm -rf tree/

mkdir

Description: mkdir makes a new directory - what could be simpler?

Command Line: Not much to speak of

Examples: To make a directory:

$mkdir mydirectory

grep

Description: grep is a powerful text search tool that can be used on files, piped streams of data, and input. grep can determine if a text string appears within the target and can return the line, the name of the file, or whatever else you want it to return.

Command Line: With all of grep’s functionality, it is a given that there are many command line options. I find one option particularly useful in common applications: -l will tell grep to return the name of the file that the string was found in, instead of what it usually returns, which is the line the string was found in.

Examples: First of all, read the examples using grep given in the section about pipes and redirectors. A simple search of a textfile:

grep barath bigtextfile.txt

find

Description: find is yet another powerful utility with many options that is still simple to use for its basic features. find can give listing of files and can search within those file listings to find files.

Command Line: The most used option is -name which then allows you to provide a filename with wildcards that you are searching for.

Examples: To find all files on the system that begin with “temp”, starting from the root directory “/” :

#find / -name temp*

ps

Description: ps allows you to see the “processes” - the programs - running on the system. ps uses a few strange terms and acronyms that I should explain. All processes on a Linux system have a job number associated with them. They can be attached to a tty, or terminal, which means they can interact with a user, or they can be detached and running in the background, even when you are logged off. You wouldn’t want to interface with a web server daemon, but you would with an email program. Thus the daemon would be in the background but the email program would be in the foreground. Let’s suppose you were running a ftp program, and were downloading a file. Instead of waiting until it completed the download before using the terminal again, you could press Ctrl-Z (which suspends the process that you are using currently) and then would type bg to background it. This would allow it to run in the background. You would see this process when you do a ps - it would show up in the listing.

Command Line: ps has five common options - a, u, x, m, and f. Newer version of ps don’t require the “-” before the options. a shows all processes on the system, u displays additional user information, and x displays an extended listing of processes, including ones that are detached. m allows the process names to stretch one line longer for each “m” you use. f provides a tree layout of the processes, so you can see which processes are owned by which other processes. When run as root, ps automatically does x

Examples: A simple example to list and classify all running processes, allow them each to extend two lines longer, and show them in a tree layout:

$ps -auxmmf

kill

Description: kill does what it means - it kills processes. There are three command reasons to use kill: 1. If a program has become idle or is no longer needed, a kill can be issued using the process’s pid (you find this using ps). 2. If a daemon or other program needs to be restarted or reset, a kill -HUP can be issued. 3. If a program has gone haywire or otherwise will not go away with a regular kill, a kill -9 can be issued.

Command Line: As described above, the two common options are -HUP and -9. -HUP restarts most daemons and other programs. -9 forces a process to be killed and does not allow it to shutdown normally. Use -9 only when a process will not die with a normal kill

Examples: To kill a process, use kill. The pid number can be obtained by running ps. This will restart process id 237:

#kill -HUP 237

gzip

Description: Those of you familiar with DOS no doubt know of pkzip - a compression and archival program. Note that pkzip compresses individual files and lumps those compressed files into one big archive file. Linux handles this differently - gzip only handles compression, and tar handles archival. Thus gzip can only compress individual files - and while it can process many files at once, they will be compressed and stored individually.

Command Line: I urge you to use gzip’s -h help feature to learn about the command line options as many of them are useful and cannot be done justice here. -d in particular tells it to decompress.

Examples: To decompress a gzipped file:

$gzip -d compressedfile.gz

tar

Description: As described with gzip, archival is separate, and tar does that. Since archival and compression together is so common, gzip usage has been integrated into tar

Command Line: To extract files with tar, use tar xvf filename.tar. To create a tar archive, use tar cvf. Note that a “z” can be added to the commands to tell tar to use gzip (de)compression.

Examples: To extract files form a tar archive, do:

$tar xvf bigarchive.tar

If a file is both .tar and .gz, which is either .tgz or .tar.gz, you can do the following to extract the files in one easy step:

$tar zxvf program-1.2.tar.gz

chmod

Description: Perhaps the most fearsome of the ‘15 core commands’, chmod is a completely new dimension for a non-unix user. Since Linux (and unix in general) is a multi-user OS, files must be kept safe from other users. Thus Linux has very tight security in which all files and directories have owners, groups, and modes for access. The owner has control over the files/dirs, the group aids in the mode process, and the mode sets who has what access to the files. When you do an ls -l, it lists this information off to the left; there will be a strange looking bar of characters like: -rw-r–r-- This means reading from left to right, that no special bit has been set, the owner can read to it, write to it, but not execute it, the group can read it, but not write to it, and not execute it, and the other users can read it, but not write to it or execute it. Think of it as groupings: first on the system.

Command Line: chmod takes options that are stuck together to tell it what to do. The first letter is a u, g, o, or a, which stand for user, group, other, or all - telling chmod whose permissions to change. Then comes a +, -, or = to add, remove, or set permissions accordingly. Lastly, there is r, w, and x, which I have described. After this compound comes the name of the file or directory.

Examples: To remove permissions for all others besides yourself:

$chmod go-rwx filename

To give everyone full permission:

$chmod a=rwx filename

To make a directory writeable but not readable:

$chmod go=w directory/

man

Description: You might think I’m sneaking in an extra command, but I’m not - man teaches you about other commands so it can’t be counted. man retrieves and displays the manual pages for just about anything. Be warned: manual pages can often confuse you more than help you as they give quite a bit of technical information.

Examples:

$man grep

Supplementary Commands In this section, I am going to outline 50 other commands that are useful in many instances. I have tried to categorize these commands and alphabetize them within these categories, and provide brief descriptions of each.

File Handling

  • cat - outputs the contents of a file or inputs into a file from the commandline
  • file - finds out what type of file something is by looking it up from/etc/magic
  • fmt - simply formats and word wraps a text file
  • head - displays the beginning of a file
  • tail - displays the end of a file
  • wc - counts the number of words, lines, or characters in a file or stream

Process Control

  • at - schedules certain commands to be executed at specific times
  • bg - places a process that has been suspended to run in the background
  • crontab - schedules certain commands to be executed at specific times on certain days or at certain times
  • fg - places a process that has been suspended or backgrounded in the foreground
  • free - displays how much memory has been used / is available
  • killall - kills all processes by a given name instead of by a PID number
  • top - displays the processes that are using the most resources

Network Functions

  • finger - finds out information about a specific user
  • frm - displays a quick listing of current mail
  • lpr - prints a document or stream
  • ping - tests the network response time of a machine
  • talk - chats directly with another user
  • traceroute - finds the route data travels to arrive at a remote host

Filesystem Management

  • chgrp - changes the group ownership of a file/dir
  • chown - changes the user/group ownership of a file/dir
  • dd - does direct data transfers, usually from diskimages to disks or vice-versa
  • df - displays the space used up on all mounted filesystems
  • du - displays the space used by directories and recursively displays the disk space taken by sub-directories as well
  • fsck - checks a filesystem for errors and fixes them
  • ln - creates a symbolic or hard file or directory link
  • locate - locates a file using a pre built file database
  • slocate - securely locates a file using a pre built file database
  • rmdir - removes a directory
  • whereis - finds an executable, source file, or man page in common paths
  • which - displays the full path of a command that is run through the path

User Management

  • ac - displays user accounting information such as login time
  • chsh - changes a user’s shell
  • last - displays the last users to login to the system
  • passwd - changes a user’s password
  • adduser - adds a user
  • su - substitutes another user’s id for the current user id
  • w - displays a list of the other users currently logged in and what they are doing
  • write - writes a message to the console of another user
  • sudo - runs the command as root

Programming / Management

  • g++ - default c++ compiler
  • gcc - default c compiler
  • ldconfig - updates the list of loadable libraries that are in the paths specified in /etc/ld.so.conf
  • make - makes a program using the commands specified in the Makefile in the current directory or with another specified file

Misc

  • clear - clears the screen
  • dpkg - debian package application, allows installation, manipulation, and deletion of .deb packages from a system
  • export - exports a shell variable so that programs that are run can access it
  • rpm - redhat package manager, allows installation, manipulation, and deletion of .rpm packages from a system
  • uname - displays system information
  • uptime - displays system uptime and load
  • xargs - passes a stream as arguments to a specified command
 
  linux_gnu_quick_commands_list.txt · Last modified: 2010/10/29 21:54
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki