Unix/Linux Reference Notes
- Basic Commands
- Command Pipelines
- Searches/Wild-cards
- File Permissions
- Unix Environment Variables
- Networking Commands
- Making ISO images
- Disk Partitions, Formatting, Etc.
- Gentoo Linux Notes
Basic Commands
Commands can often be used with arguments or options.
Words in italics are argument/option variables.
| Unix Command | Usage |
pwd | Prints the current ("working") directory path to the screen. |
date | Shows current date and time. |
who | Lists the users logged in, how they're logged in, and when they started their session. Add -H for headers. |
who am i | Gives above information but only for you. |
ls | Lists files in working directory. Does not show invisible files. |
ls -a | Lists all files in working directory. |
ls -al | Lists all files in working directory, with Mode bit settings, the number of links to the files, Owner ID, Group ID, File Size (exact count in bytes), and Date/time of last modification. |
ls directory | Lists files in directory. |
cd | Changes the working directory to your home directory. |
cd directory | Changes the working directory to directory |
mkdir directory | creates directory |
echo $VarName | Prints the value of VarName |
cat filename | Prints filename to screen |
cat file1 file2 | Combines file1 and file2. Must be piped into something else. |
cat file1 file2 > File3 | Combines files 1 and 2 into file3 |
cp sourcefile targetfile | Makes a copy of sourcefile called targetfile |
cp file. | Copies file to current directory, where file is the full pathname of the file. |
ln AbsolutePath LinkName | Creates a link to file described by AbsolutePath. The link is placed in the working directory and called LinkName. Use only when the file and the working directory are on the same file system. |
ln -s AbsolutePate LinkName | Creates a link to file described by AbsolutePath. The link is placed in the working directory and called LinkName. This link is based on the file's pathname and not its inode number. Use when file and working directory are on different file systems or when you're not sure. |
mv file1 file2 | renames file1 to file2 |
mv file directory | moves file to directory. |
passwd | Change your password. |
rm filename | Deletes filename. It works with directories too, but they must be empty. You can remove files you don't own if they are in a directory in which you have write permission (see section of file permissions.) rm will ask you to confirm the removal. Answer with y/n. Adding the argument -f will cause rm to not ask for confirmation. |
rm -rf directory | Deletes all contents of directory and the directory itself. Remove the f argument and it will ask you for confirmation of individual items. |
mailx | Read mail. Press ? for help. |
mailx username | send mail to a user. |
elm | A better, more user friendly e-mailer. |
stty sane | Returns terminal to a "stable" state. Use if terminal is not functioning properly. After typing this you should log off and log back in. |
umask | use to set or see current mask settings. See section on file permissions for usage. |
chmod PermNum file/directory | Use to set the permissions of file/DirName to PermNum. See section of file permissions for more on permission numbers. |
chown NewOwner file | Change the owner of FileName to NewOwner. To use, you must be the current owner or a superuser. The input of NewOwnder should be the new owner's login name. |
chgrp NewGroup file | Works like chown but for groups. |
file FileName | Tells a file's type. (Directory, Regular File, Link, Etc.) |
wc file | Tells the number of Lines, Words and Bytes in file--in that order. |
more file | Use to page a file too large to fit on your screen all at once. Press q to quit, h for help. |
man command | Use to detailed help with command. Press q to quit, h for help. |
Command Pipelines
You can use a Unix feature called a pipe to direct the output from one program into another. The symbol for the pipe is the vertical bar ( | ). The resulting command is called a pipeline.
An example of it's use would be to use more to paginate the contents of a large directory.
ex:
ls -al | more
Searches/Wild-Cards
Wildcard Characters:
| Metacharacter | Matches |
| Any single character (except an initial .) | |
| Any sequense of characters, including none. | |
| Any character from the class s. |
File Permissions
| Type | File Action | Directory Action |
| read (r) | Allows file to be viewed, copied, and printed. | Allows directory to be listed |
| write (w) | Allows file to be moved, removed, and modified. | Allows files to be created in directory |
| execute (x) | Allows file to be run as a command. | Allows directory to be searched. |
| Mode | User | Group | Other |
The mode bit indicates the type of file. A dash indicates a normal file, a
d indicates a directory, and other codes indicate various kinds of device files and other special purpose files.
| Mode | Octal |
| --- | 0 |
| --x | 1 |
| -w- | 2 |
| -wx | 3 |
| r-- | 4 |
| r-x | 5 |
| rw- | 6 |
| rwx | 7 |
A '-' means that the option is off.
Using "umask"
umask is used to check and set the mask value. The mask value is combined with the standard unix base directory and file defaults (777 and 666, respectively) to effectively create a new default. This new default will be applied whenever a new file or directory is created.
For Directories:
| User | Group | Other | |
| Base directory default (777) | rwx | rwx | rwx |
| Mask Value (027) | --- | -w- | rwx |
| New directory default (750) | rwx | r-x | --- |
For Files:
| User | Group | Other | |
| Base file default (666) | rw- | rw- | rw- |
| Mask Value (027) | --- | -w- | rwx |
| New file default (750) | rwx | r-x | --- |
Unix Environment Variables
Use echo to see the current setting of these variables.
| Variable | Meaning |
| $PATH | All directories other than WD unix searches when a command request is made. |
| $TERM | The current terminal setting. |
| $HOME | Your home directory. |
Networking Commands
| Unix Command | Usage |
ping host | Sends a ping to host. Host can be either an IP address or a host URL. |
traceroute host | Reports all hops between you and host |
ftp host | |
telnet host | |
ssh host |
Make an ISO image
To make an ISO from your CD/DVD, place the media in your drive but do not mount it. If it automounts, unmount it.
dd if=/dev/dvd of=dvd.iso # for dvd
dd if=/dev/cdrom of=cd.iso # for cdrom
dd if=/dev/scd0 of=cd.iso # if cdrom is scsi
To make an ISO from files on your hard drive, create a directory which holds the files you want. Then use the mkisofs command.
mkisofs -o /tmp/cd.iso /tmp/directory/
This results in a file called cd.iso in folder /tmp which contains all the files and directories in /tmp/directory/.
Disk Partitions, Formatting, Etc.
Use fdisk /dev/hda to partition drive hda, make changes, or view the partition table.
| Filesystem | Creation Command |
| ext2 | mke2fs |
| ext3 | mke2fs -j |
| reiserfs | mkreiserfs |
| xfs | mkfs.xfs |
| jfs | mkfs.jfs |
mkswap /dev/hd__ is the command used to initialize swap partitions and
swapon /dev/hd__ is used to activate it.
Partitions need to be mounted via the mount command:
mount /dev/hd__ mountpoint path

