Part 2: Basic System Maintenance
Using find to search for files
The most common way of using find is:
find /path/to/search/directory -name "filename"
find /home/pink -name "*.png"
Will search for all the files with the .png extension in pink's home directory. Notice the star (*), which is a wildcard, and stands for 'any number of characters or no character'. The same result can be obtained by replacing pink with $USER, but first try:
Which will echo the username of the person currently logged on at the shell. Let's say you want to search for all the files in your home directory which have digits in them. You'll do:
find $HOME -name "*[0-9]*"
The [0-9] is also a wildcard, like *, and the shell will expand it into all the digits from 0 to 9. *[0-9]* practically tells find to search for any file which has one or more numbers in it.
Using tar and gzip
tar is a GNU utility for archiving files and directories, that is, it creates from many files one single file, with the .tar extension. tar doesn't compress the files, it only archives them. To archive a directory and all the contents in it, do:
tar -cf folder.tar folder_to_archive
Then, to compress the archive and obtain a .tar.gz file, use:
To uncompress a .tar.gz file, you can do:
tar -xf folder.tar.gz
Also see the bzip2 utility (man bzip2), which is slower but provides higher compression ratios.
According to date manual page, it's an utility which can print or set the system date and time.
Wed May 28 14:25:37 EEST 2008
To change system's date and time, use:
date --set="Wed May 29 14:25:37 EEST 2008"
You have to be root in order to change system date. If you're online all the time, you won't need this. Just install ntpdate, which will synchronise the system's date and time from the internet.
Aliases are user-defined shortcuts for commands. For example, let's say you backup the file /home/$USER/personal_thoughts.txt very often. You would usually do a:
cp personal_thoughts.txt /backup/whatever/directory
cd without parameters changes current working directory to your home directory. Instead of that command, you can add an alias to your .bashrc file like this:
alias bp='cp $HOME/personal_thoughts.txt /backup/whatever/directory; echo "Backup done"'
Save the file, log out and back in (use exit or CTRL+D) and type bp. You'll see it executes the commands specified by the alias in your .bashrc file. You can find a more detailed tutorial on aliases here.
Nano is a simple and user-friendly, CLI (Command Line Interface) text editor. It comes installed by default on most distributions out there. To create a new file type:
Add some stuff into your new file, save it (^O - which is CTRL+O) and then, to quit it, use ^X. For viewing files without editing them, you can use cat and less. To exit the less utility, use Q, and to navigate through it, use the Emacs shortcuts (^N for next line, ^P for previous line, ^V for next page, ALT+V for previous page). J for next line and K for previous line will work too.
Updated: Jun 14, 2008 (Created: May 28, 2008)