Linux Quick Reference
I only use Linux to SSH to the server at work, but I find that keeping a reminder of a few of the most common commands at hand is really useful. Here's my cheat sheet.
man : display the manual for a command
Most of the commands in Linux have a "man" page where you can get information about what the command does and how to use it. To bring up the man page for the cd command, type:
# man cd
ls : list directory contents
To list files and directories in the current directory:
# ls
To list files and directories in the current directory, including details such as permissions, ownership, last modification time, etc:
# ls -l
To list all files in the current directory, including hidden files that begin with a ".":
# ls -a
To list files in the directory /home/my_dir:
# ls /home/my_dir
Options can be combined and paired with a directory. To list all files and directories, including details, in /home/my_dir:
# ls -la /home/my_dir
cp : copy files and directories
Copy file file1 to file2:
# cp file1 file2
Copy file file1 to file2, preserving ownership, group and mode properties:
# cp -p file1 file2
Copy directory dir1 to dir2:
# cp -r dir1 dir2
Copy all files in one directory to another, omitting other directories in the source directory:
# cp sourcedirectory/* targetdirectory
chmod : change permissions
chmod can be given base 8 (octal) values to change the permissions of a file or folder.
The read, write & execute permissions are assigned the following values: read=4, write=2, execute=1.
These values can be added together to set the combined permissions for reading, writing and executing, as follows:
7 = rwx, 6 = rw-, 4 = r--, 5 = r-x, 3 = -wx, 2 = -w-, 1 = --x, 0 = ---.
An example, change the permissions of myfile.txt so that they are -rwxr-xr-x:
# chmod 755 myfile.txt
chmod can take other argument types, but I prefer to use these octal values, which admittedly might seem confusing at first.
|