Professional Documents
Culture Documents
Changing Directories:
- cd “directory name” (e.g. cd /home)
- pwd (tells you what directory you are currently in)
- cd .. (goes out of your current directory)
- cd will bring you to your user’s home directory
Directory Contents:
- ls (will show you the files and/or directories in your location)
- ls –a (will also show hidden files)
- Not sure how to spell the directory?
- start typing the beginning and press tab (file should come up)
- e.g. type cd m and press tab a few times (all files with m come up)
- ls –l (this will give you more details about your directory contents)
- the command dir will also do the ls command
Adding an alias:
- go to your home directory (e.g. cd /home/dustin)
- find .bashrc (type ls –a to find it)
- type vi .bashrc
- type alias mv=‘mv –i’ (anything can be substituted there)
- exit and save
- type source .bashrc
Copying a File:
- type cp “file name” “new file name”
- e.g. cp crazy crazy2
Moving a File:
- type mv “file name” “location”
- e.g. mv craziness /home
Removing a File:
- type rm “file name”
- e.g. rm testpage
- type rm * -f to remove everything with no questions asked
- To remove a directory and everything inside of it:
- rm –rf “directory name”
Making a Directory:
- type mkdir “directory name”
- e.g. mkdir myfiles
Removing a Directory:
- type rmdir “directory name”
e.g. rmdir myfiles
- Note: You can’t remove directory unless it is empty
Piping Commands:
- To connect commands, use the vertical line
- e.g. ls –l | more
- this list the contents of the directory (ls –l) with the more command
- Page-Up and Page-Down work with scrolling through a long list after more
Retrieving Documentation:
- Many different ways
- type man “command” (e.g. man cp)
- type “command” –help (e.g. cp –help)
- type info “command” (e.g. info cp)
- type apropos “command” (e.g. apropos cp)
- apropos gives you available manuals based on your typed word
Touch Command:
- touch can be used to create a file
- e.g. touch crazyfile
- touch can also alter a file’s creation date
- e.g. touch –t 04090912 crazyfile.txt
Find Command:
- find command can find files
- e.g. find –name cr* (all files beginning with cr will come up)
- another example: find –mmin +0 –mmin -10
- this brings up all files created and/or worked on in last 10 minutes
Grep Command:
- searches inside the files
- e.g. You have three files with the word Mary in them
- type grep Mary mary*.txt
- all three files get returned
- only one of those files has the word cow in it
- grep cow mary*.txt
- only one file gets returned
Alternative to Tee:
- you may use the > symbol to perform tee
- e.g. ls –l > directory_listing
- you can stamp a date as well
- e.g. date >> directory_listing
- both greater than symbols with add, one will overwrite
2> Command:
- this command is used for creating a file for an error
- e.g. crazyfile 2> program_X_error
- error message will be saved
Whoami Command:
- this tells you who the current user is
- type whoami
Whatis Command:
- this tells you what a command is used for
- e.g. whatis cp
Whereis Command:
- this is used to find the exact location of a program
- e.g. whereis vi
- similar command is which
- e.g. which vi
Echo Command:
- used mainly in shell scripts to repeat what you have typed
- e.g. echo hello
- echo can be used for other things
- e.g. echo Russell owes me money | tee –a russellnote.txt
- this create a text file with the note you typed
WC Command:
- this command tells you the number of lines, words, and characters in a file
- e.g. wc crazyfile.txt
Date Command:
- type date to get today’s date
- to find out what day of the week a date falls on:
- e.g. date --date ‘Feb 28’
- to get a calendar:
- e.g. cal 2 2006
Exiting:
- exit will get you out of the x-window
- logout will allow you to switch users
Formatting a Floppy:
- insert floppy disk
- type mke2fs /dev/fd0 and press enter
- type e2fsck /dev/fd0 and press enter
Mounting a Server:
- To mount a server:
- type mkdir /ts
- type mount 10.0.1.5:/ts /ts
- Note: Replace the IP with your appropriate IP
Unmounting File Systems:
- To unmount a CD:
- type umount /media/cdrom (or cdrecorder)
Tip on Mounting:
- If you’re trying to unmount something but refuses to do so, here are some steps:
- Make sure you are not inside the area you are trying to unmount (pwd)
- type lsof | grep cdrec
- this will show a list of open files from the cdrom
- at this point, you can kill any open files and unmount it
File Permissions:
- permissions are done in 3-part 4-2-1 setup
- the 3 parts, in order, are Owner, Group, and Others
- 4 represents read, 2 represents write, 1 represents execute
- e.g. chmod 755 crazyfile
- this means the owner has full rights, while the group and others can read
and execute, but can NOT write (4 + 1 = 5)
- e.g. chmod 644 awesomefile
- owner can read and write, while group and others can only read
Backing Up Files:
- When you have a number of files and you want to combine them in a single file
- type tar –cvf “file created” “files”
- e.g. tar –cvf linuxnotes.tar notes*.txt
- this will take all files named notes and tar them into linuxnotes.tar
- this does NOT compress the files
- To compress the file, you must now zip it
- type gzip “file name”
- e.g. gzip linuxnotes.tar
- Tip: Tar and Zip can be done in one step
- e.g. tar –czvf linuxnotes.tar.gz notes*.txt
Network Configuration:
- multiple options:
- type in netconfig
- small screen will appear to configure network
- Use the GUI and go to network in system settings
- Go into etc/sysconfig/network-scripts and vi into ifcfg-eth0
Troubleshooting Tip:
- Getting an unknown error?
- go into /var/log
- type tail messages
- e.g. tail –n 100 messages | less (last hundred messages)
- tail –f messages (places message log in real time)
Delegating Authority:
- As the root user, you can choose what other users can do
- For example:
- type visudo
- Under user alias specification, give trusted users
- e.g. User_Alias TRUSTED = dustin
- Under cmnd alias specification, give commands to be used
- e.g. Cmnd_Alias TOOLS = /bin/mount, /bin/umount
- Under user privilege specification
- e.g. TRUSTED ALL = TOOLS
Changing Users:
- su will allow you to work as the root user
- e.g. su, type password
- e.g. su dustin (if you were root, a password will not be needed)