Basic Linux

Many notes can be writen about basic use of linux, I have chosen a few that I think is important.

Moving around

ls - Lists files and folders ind a directory
ls -a - Lists also hidden files
ls -lah - Shows a lists of files and directories and their size

cd - Change directory
cd .. - Changes the directory one folder up
cd folder1 - Changes the directory to folder1

File handling

mkdir folder1 - Creates directory folder1

mv file1 file2 - Renaming file1 to file2
mv file2 folder1/ - Moving file2 into folder1

cp file1 folder1/ - Coping file1 into folder1
scp user1@host1:test1.txt . - Coping test1.txt from homedir of host1 to current folder

rm file1 - Removing file1
rm -r folder1 - Removeing folder1 (r for recursive)
rm -rf folder1 - Removing folder1 and all its content, even if there is hidden files

File viewing

less file1 - Shows the content of file1 in a nifty file viewer
head -n 10 - Shows the first 10 lines of file1
tail -n 10 - Shows the last 10 lines of file1

File permissions

File permissions is in a basic Linux system changes with the command chmod [options] [files].
The options describes the changes wanted.
Who: What:
------------------------------
u -> user r -> read
g -> group w -> write
o -> other x -> execute
a -> all

chmod a+x - Makes the file executable for all users
chmod o-r - Makes the file unreadable for others

Symbolic links

A symbolic link is a kind of shortcut. Is can be to a folder or a file.
ln -s folder1/file1 file2 - This makes a symbolic link named file that points to file1
ln -s folder1 file1 - A shorter way of making a symbolic link of the same name in the current directory

Bashrc

It is possible to execute commands, when a terminal is started, this is down by adding it to .bashrc in your home directory.
echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc - Adds all executable files in the directory ~/bin to $PATH
This mean you can run them like any other program.

Searching for help

man program_name - Shows the manual for the program
program_name --help - A standard way of displaying a small help

Gentoo tools

revdep-rebuild
This tool is Gentoo's Reverse Dependency rebuilder. It will scan your installed ebuilds to find packages that have become broken as a result of an upgrade of a package they depend on. It can emerge those packages for you but it can also happen that a given package does not work anymore with the currently installed dependencies, in which case you should upgrade the broken package to a more recent version. revdep-rebuild will pass flags to emerge which lets you use the --pretend flag to see what is going to be emerged again before you go any further.

Further infomation at: http://www.gentoo.org/doc/en/gentoolkit.xml

Space info

df -h -> gives the space on the harddisk

du -s [foldername] gives the size of the folder

Grep

grep -ir [The word you seek] *
i = case insensetiv
r = reursiv
n = line number
* = The directory and forward

This will find 'stupid program' in the files included in report.tex and show whitch file the stupid program is in
latex report.tex | grep 'stupid program'\|\.tex

Encoding

To convert between to different character encodings use the following commands:
recode latin1..utf-8 - From latin1 to UTF-8
recode utf-8..latin1 - From UTF-8 to latin1

Finding the size of a directory

$ du
Typing the above at the prompt gives you a list of directories that exist in the current directory along with their sizes. The last line of the output gives you the total size of the current directory including its subdirectories. The size given includes the sizes of the files and the directories that exist in the current directory as well as all of its subdirectories. Note that by default the sizes given are in kilobytes.

$ du /home/david
The above command would give you the directory size of the directory /home/david

$ du -h
This command gives you a better output than the default one. The option '-h' stands for human readable format. So the sizes of the files / directories are this time suffixed with a 'k' if its kilobytes and 'M' if its Megabytes and 'G' if its Gigabytes.

$ du -ah
This command would display in its output, not only the directories but also all the files that are present in the current directory. Note that 'du' always counts all files and directories while giving the final size in the last line. But the '-a' displays the filenames along with the directory names in the output. '-h' is once again human readable format.

$ du -c
This gives you a grand total as the last line of the output. So if your directory occupies 30MB the last 2 lines of the output would be

30M .
30M total

The first line would be the default last line of the 'du' output indicating the total size of the directory and another line displaying the same size, followed by the string 'total'. This is helpful in case you this command along with the grep command to only display the final total size of a directory as shown below.

$ du -ch | grep total
This would have only one line in its output that displays the total size of the current directory including all the subdirectories.

remembering the rignt program

If you cant remember the name of a program, use
ctrl + r [the letter you think the program starts with]
otherwise use
http://freshmeat.net/
http://sourceforge.net/
to refresh your memory

find

Search for the file names "myletter.doc" inside my home directory and print the result to the screen:
find ~ -name myletter.doc -print

Search for the file and folder names "mysql*" starting from the root directory and everywhere within it and print the result to the screen. (use "sudo" to get root access temporarily.):
sudo find / -name mysql -print

Search for the file names "myletter.doc" inside the current directory and print the result to the screen:
find . -name myletter.doc -print

Search for the file names starting "myletter" inside the current directory and print the result to the screen:
find . -name 'myletter*' -print