Appendix A. Linux Commands

alias

Creates a command that runs other commands. Aliases are a handy way to customize your system and to provide shortcuts for common activities. For example, the following alias creates an easy-to-remember name for unpacking a compressed archive:

alias extract='tar zxovf'

Put an alias into the file /etc/bashrc if you would like the alias to be always accessible to all users on the system. Type alias alone to see the list of aliases for your account. Use unalias to remove an alias.

alias ls="ls --color=tty"

Creates an alias for the command ls to enhance its format with color. In this example, the alias is also called ls and the color option is evoked only when the output is done to a terminal (not to files).

apropos topic

Shows which man (documentation) pages cover the topic specified.

bash filename

Runs a script, or file containing bash shell commands.

bunzip2 filename .bz2

bunzip2 stands for big unzip. The command decompresses files with the extension .bz2. Such files have been zipped with bzip2 compression utility, which is usually reserved for large files and/or directories.

cat filenames

Combines all listed files in order and displays them on the screen. Useful for showing plain text files; if they are long, they should be displayed with less or more. Also often used to combine files into a single file specified after a > character, as in:

cat a1 a2 a3 > complete_file
cd directory

cd stands for change directory. For example, if you want to change to a sub-directory in your home directory, you could issue the command cd Documents. Using cd without the directory name takes you to your home directory. Using cd with the slash (cd /) takes you to the root of the system directory.

cd .

Takes you to your previous directory; a convenient way to toggle between two directories.

cd ..

The two periods take you one directory up—for instance, from /home/tadelste/subdir to /home/tadelste.

CTRL-c, CTRL-z, CTRL-s, and CTRL-q

Invoked by pressing the CTRL key. Respectively, these stand for stop the current command, suspend current command, stop the data transfer, and resume the data transfer.

cp source destination

Copies files. For example:

cp /home/sam/filename.

copies a file to the current working directory (denoted by the final period). Use the -R option to copy the contents of whole directory trees. Thus:

cp -R my_existing_dir/ ~

copies a subdirectory under the current working directory to the home directory.

chmod perm filename

chmod stands for change mode. Changes the file access permission for the files you own (unless you are root, in which case you can change any file). You can make a file accessible in three modes—read (r), write (w), and execute (x)—to three classes of users: owner (u), members of the group that owns the file (g), and others on the system (o). The letter a refers to all modes or all users.

chmod g+w filename

Makes the file available for writing to members of the group that owns it.

chmod a-x filename

Removes the permission from all users to execute the file filename.

chmod o-x filename

Adds permissions to just the owner to execute the file filename.

chown new_ownername filename

chown stands for change owner. Changes the ownership of a file or directories. A recommended practice is to use chown username:usergroup filename, which sets a new owner and group at the same time.

date

Shows current date and time. The root user can use this command to reset the date and time.

dd if=/dev/fd0H1440 of=floppy_image , dd if=floppy_image of=/dev/fd0H1440

dd stands for data duplicator. Create an image of a floppy (/dev/fd0H1440) to the file called floppy_image in the current directory. Then (presumably after removing the floppy disk and inserting another) copy the file to the floppy disk.

dmesg | less

Prints kernel messages seen at boot time. Use less/var/log/dmesg to see what dmesg put into this file after the most recent system bootup.

eject

Ejects the CD-ROM tray. This command defaults to the CD-ROM, but could be used to eject other removable media by specifying the mount point or device—for instance: eject/dev/floppy.

fg %job

Puts a job in the foreground after it has been placed in the background (usually by issuing it with a trailing & character). Jobs are numbered, starting from 1.

find / -name filename

Finds the file called filename on your filesystem, starting the search at the very top from the root directory. The filename may contain wildcards (*,?). For example, docu_*.txt refers to any file that begins with docu_ and ends with .txt.

find ~ -name filename

Searches for filename starting from your home directory and searching all sub-directories under it.

gunzip filename .gz

Decompresses a file that was compressed with gzip. The command is pronounced “gee unzip.”

halt or reboot

Issued as root. Halt or reboot the machine.

history

Shows a list of previously issued commands.

ifconfig

Issued as root. Displays information on the currently active network interfaces. The first Ethernet card displays as eth0, the second as eth1, etc. The interface lo stands for the loopback interface, which should be always active.

init 6

Reboots the machine into single-user mode. Used to perform system administration or other tasks that require all users to be logged out.

jobs

Shows jobs that have been placed in the background by issuing them with a trailing & character.

kill PID

Forces a process shutdown. First, determine the PID of the process to kill using ps -aux.

less filename

Scrolls the content of a text file. Press q when done. less is roughly equivalent to the more command but has extra options.

ln -s source destination

Creates a symbolic or soft link called destination to the file source. The symbolic link just specifies a path where to look for the real file.

ls directory

Lists the contents of the specified directory. Can also be used to list specific files, or issued without arguments to show the contents of the current directory.

ls -al |more

Lists the contents of the current directory in a long format that shows extra information, such as who owns the file and the access permissions.

If a file is accessible to all users in all modes, the leftmost columns of the output shows:

-rwxrwxrwx

The initial hyphen can sometimes be another character, such as CW for directory. The next triplet shows the file permissions for the owner of the file, the next triplet for the group that owns the file, and the final triplet for others (or the rest of the world). When permission is denied, the ls command shows a hyphen.

mkdir directory

Makes a new directory. You can use this in your home directory to create a subdirectory. As root, you can make a directory regardless of permissions.

more filename

Similar to less. Terminates when you reach the end of the file or files.

mount -t auto /dev/fd0 /mnt/floppy

Issued as root. Mount a floppy disk. The directory /mnt/floppy must exist and must not be your current directory. The type of the filesystem will be automatically detected. Before trying to remove the disk, issue the amount command.

mount -t auto /dev/cdrom /mnt/cdrom

Issued as root. Mount the CD. The directory /mnt/cdrom must exist and must not be your current directory. Before trying to remove the disk, issue the amount command.

umount /mnt/floppy , umount /dev/cdrom

Unmounts the floppy or CD-ROM. Note that the umount command is missing an n. Depending on your setup, you may not be able to unmount a drive that was mounted by somebody else.

mv source destination

Moves or renames files. The same command is used for moving and renaming files and directories.

passwd

Changes your password. You are prompted for it twice, to make sure you enter the password correctly as you meant to enter it.

passwd user_name

Issued as root. Creates or changes a password for an existing user.

ping machine

Checks if you can contact another machine (through the machine’s name or IP address). If the network is operating and you can reach the machine, a series of messages are sent and the results are printed. Press CTRL-C to terminate the command.

ps

Stands for print status or process status. Displays the list of currently running processes with their process ID numbers. Issued without arguments it shows only those commands started from the current shell.

ps aux | less

Lists all the processes currently running on the system, together with the name of the user who owns each process. Using less allows you to scroll up and down in the process list.

pwd

Displays the name of your current directory. This allows you to see your position in the directory tree.

rm filenames

Removes or deletes files. You must own the file (or be root) in order to remove it. Warning: there is no reasonable way to recover removed files. Use the -i option if you would like to be prompted before each file is removed.

rm -r directory

Removes a directory and all its contents. Can be dangerous because you don’t see exactly what is being removed unless you add the -i option.

rmdir directory

Removes an empty directory. Use rm -r (after careful thought!) to remove a directory that has files or subdirectories in it.

shutdown -h time

Issued as root. Bring the system down to a halt. The preferable way to shutdown the system using the command line. The time specifies a delay so that users can wrap up their work and log off; if you are the only user, you can specify now for the time.

su user_name

Stands for substitute user ID. You need to enter the user’s password. When issued without arguments, it allows you to become root (if you have the privileges to do so). Type exit to return you to your previous login. Don’t habitually work on your machine as root. The root account is for administration and the su command is to ease your access to the administration account when you require it.

tar zxvf filename .tar.gz

Stands for tape archiver. Useful to unpack a tarred and compressed tarball (a file with a .tar.gz or .tgz extension) that you download from the Internet.

tar xvf filename .tar

Unpack a tarred but uncompressed tarball (a file).

unzip filename .zip

Decompress a file (a .zip file) zipped with the ZIP compression utility, usually from a Windows computer.

useradd user_name

Issued as root. Creates an account for a user.

useradd -m -g authors sam

Issued as root. Creates an account called sam. The -m option creates a home directory, and the -g option assigns sam to the authors group.

userdel user_name

Issued as root. Removes an account. The user’s home directory and the undelivered mail must be removed manually.

which executable_name

Shows the full path to the executable that would run if you typed its name on the command line.

whereis command

Prints the locations for the binary, source, and manpage files of the command command.

whoami

Prints your login name. Often used when several windows are open, and one may be a root account or an account on a remote system.

zcat filename .gz | more

Stands for zip cat. Displays the contents of a compressed file. Other utilities for operating on compressed files without an extra decompression step are also available: zless, zmore, zgrep, etc.

zip filename .zip filename1 filename2

Compresses the two files filename1 and filename2 to a zip archive called filename .zip. To zip a whole directory, add the -r option.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.239.41