This is a draft cheat sheet. It is a work in progress and is not finished yet.
Rebooting and Shutting Down
shutdown at 10:00 |
$ sudo shutdown -h 10:00 |
shutdown now |
$ sudo shutdown -h now |
restart at 10:00 |
$ sudo shutdown -r 10:00 |
restart now |
$ sudo shutdown -r now |
with message "Shutting down for scheduled maintenance. |
$ sudo shutdown -h 10:00 "Shutting down for scheduled maintenance." |
Locate application
locate application only |
which "application name" |
locates application , source and man |
whereis "application name" |
Locate / Find
The locate utility program performs a search through a previously constructed database of files and directories on your system, matching all entries that contain a specified character string
updatedb to update the database
can use grep program as a filter; grep will print only the lines that contain one or more specified strings
$ locate zip | grep bin |
Finding Files
Searching for files and directories named "gcc" |
find /usr -name gcc |
Searching only for directories named "gcc": |
find /usr -type d -name gcc |
Searching only for regular files named "gcc" |
$ find /usr -type f -name gcc |
*To find files based on time created "+_ n" days |
find / -ctime n |
To find files based on size +- n |
$ find / -size n |
Another good use of find is being able to run commands on the files that match your search criteria. The -exec option is used for this purpose.
To find and remove all files that end with .swp:
$ find -name "*.swp" -exec rm {} ’;’
*mtime for modified/written time
atime for access time/read time
|
|
Accessing Directories
Displays the present working directory |
pwd |
Change to your home directory |
cd ~ or cd |
Change to parent directory |
cd .. |
Change to previous directory |
cd - |
Exploring the FileSystem
Changes your current directory to the root (/) directory (or path you supply) |
cd / |
List the contents of the present working directory |
ls |
List all files including hidden files and directories (those whose name start with . ) |
ls –a |
Displays a tree view of the filesystem |
tree |
Directories
to create a directory. |
mkdir |
create a sample directory named sampdir under the current directory, |
mkdir sampdir |
create a sample directory called sampdir under /usr |
mkdir /usr/sampdir. |
Removing a directory * |
rmdir |
To remove a directory and all of its contents |
rm -rf |
* for rmdir The directory must be empty or it will fail
* usage sample for rmdir and rm -rf is same as mkdir
Renaming / removing directory
Rename a directory |
mv |
Remove an empty directory |
rmdir |
Forcefully remove a directory recursively |
rm -rf |
Basic Packagaing Commands
Install package |
dpkg --install foo.deb |
Install package, dependencies |
apt-get install foo |
Remove package |
dpkg --remove foo.deb |
Remove package, dependencies |
apt-get autoremove foo |
Update package |
dpkg --install foo.deb |
Update package, dependencies |
apt-get install foo |
Update entire system |
apt-get dist-upgrade |
Show all installed packages |
dpkg --list |
Get information on package |
dpkg --listfiles foo |
Show packages named foo |
apt-cache search foo |
Show all available packages |
apt-cache dumpavail foo |
What package is file part of? |
dpkg --search file |
|
|
Viewing Files
for viewing files that are not very long; it does not provide any scroll-back. |
cat |
o look at a file backwards, starting with the last line |
tac |
Used to view larger files |
less (/ for forwad and ? for backward) |
Used to print the last 10 lines |
tail |
Used to print the first 10 lines |
head |
Used to print the last X lines |
tail -n X or tail -X |
Used to print the first X lines |
head -n X or head -X |
File Linking
Hardlink file1 and file2 |
$ ln file1 file2 |
Softlink file1 and file2 |
$ ln -s file1 file2 |
New file / change time of file
Create newfile |
$ touch "filename" |
sets the "myfile" file's time stamp to 4 p.m., March 20th (03 20 1600). |
$ touch -t 03201600 myfile |
Removing/Renaming file
Rename a file |
mv |
Remove a file |
rm |
Forcefully remove a file |
rm –f |
Interactively remove a file |
rm –i |
|