Linux Basics

Starting a journey with linux can be tough at times, especially when you are no tech pro. Yet, it’s worth taking a while to get to know this system and it’s basics. Maybe someday you will switch to, say, Ubuntu instead of pricey Windows. Who knows? ;)

Nowadays, Linux is not a command shell handled with bunch of unclear commands. It’s now beautifuly designed, fast and handy OS, just take a look on Fedora or Ubuntu. But, there is always a but ;) Raspi cannot handle such eye-candy OS, so we have to go with light but amazingly fast distros like Raspbian, raspbmc. Thus most of maintenance have to be done through mentioned command shell. But fear not, once you learn below basics you’ll be all set to comfortably use linux command shell. I tired to make it as complete as possible, yet if I missed something, failed to explain or so, let me know in comments area what you think, I’ll appreciate any help.

Run console application if your raspi is connected to monitor, mouse, keyboard etc. or connect to it using Putty.

1. Directories

Linux uses different structure of directories from what structure windows uses. Main folder is /, you cannot go higher than that. It’s called root folder, for example, /home/pi/importantstuff.pdf shows full path to importantstuff.pdf file in pi’s home directory under root directory. There are also two special directories:

. – dot. This is current directory, so ./importantstuff.pdf tells you to search for importantstuff.pdf in current working directory

.. – double dot. This is parent directory, going up if you like.

~ – tilde. This represents your home directory, e.g. home directory for user pi is /home/pi/

/bin – important binary applications
/boot – important filles that linux needs to boot
/dev – the device files
/etc – configuration files, startup scripts
/home – users home directories
/lib – system libraries
/media – mounted media such as pendrives, CDs
/mnt – all mounted filesystems
/opt – installed optional applications
/proc – currently running processes
/root – root user home directory
/sbin – important system binaries
/sys – system files
/tmp – temporary files
/usr – applications and files for all users
/var – variable files such as logs

2. Basic commands

Just basic commands that allows to move around in directories and do basic operations on files/directories.

ls (list). Lists filest and directories that are in your current directory.

Downloads nzb.sh nzbget sb.sh script sickbeard unrar-nonfree xbmc-backup.tar.gz

But beware, ls do not in fact list ALL your files and directories, by default hidden objects remain hidden. File or directory is considered hidden when first character of its name is . (dot). To list also such objects you have to use -a parameter:

. .bash_history .bashrc .configureduser .soft .xbmc Downloads nzbget script unrar-nonfree

.. .bash_logout .bootstatus .profile .upgrade .xbmc-current nzb.sh sb.sh sickbeard xbmc-backup.tar.gz

To list all attributes of files you should use -l parameter:

drwx------ 3 pi pi 4096 Jan 5 13:40 Downloads

-rwxr-xr-x 1 pi pi 25 Feb 9 15:30 nzb.sh

-rw------- 1 pi pi 330 Feb 20 17:11 nzbget

-rwxr-xr-x 1 pi pi 28 Feb 9 15:31 sb.sh drwx------ 2 pi pi 4096 Jan 5 13:27 script

-rw------- 1 pi pi 3494 Feb 20 17:11 sickbeard drwxr-xr-x 3 pi pi 4096 Jan 5 19:31 unrar-nonfree

-rw------- 1 pi pi 798710 Feb 18 19:51 xbmc-backup.tar.gz

And parameters are, in order: permissions, owner, group, size, date of last change and file name. You can also use many other parameters, those are only most commonly used ones, to list all use ls –help.

mkdir (make directory). Creates subdirectory in your current directory, for example:

pi@raspbmc:~$ mkdir temp pi@raspbmc:~$ ls

Downloads nzb.sh nzbget sb.sh script sickbeard temp unrar-nonfree xbmc-backup.tar.gz

cd ( change directory). This is self explanatory, changes directory :)

pi@raspbmc:~$ cd temp pi@raspbmc:~/temp$

pwd ( print working directory). Prints your current working directory.

pi@raspbmc:~/temp$ pwd

/home/pi/temp

cp (copy). Makes a copy of file.

pi@raspbmc:~/temp$ ls file1.txt pi@raspbmc:~/temp$ cp file1.txt file2.txt pi@raspbmc:~/temp$ ls file1.txt file2.txt

Cp will not ask you if it should overwrite file if destination file already exists. You have to know what you are doing because there is no easy way to recover file after overwritting or deleting (believe me, I know something about it ;) ). To make sure that you will never accidentally overwrite any file you can use cp with -i parameter. Cp will ask you if should overwrite, Y(es) accepts N(o) denies.

pi@raspbmc:~/temp$ cp -i file1.txt file3.txt cp: overwrite `file3.txt'?

mv (move). This command moves a file from one place to another.

Downloads file3.txt nzb.sh nzbget sb.sh script sickbeard temp unrar-nonfree xbmc-backup.tar.gz pi@raspbmc:~$ mv file3.txt temp/

pi@raspbmc:~$ cd temp pi@raspbmc:~/temp$ ls file1.txt file2.txt file3.txt

You can define also as a second parameter new name for a file, in other words you can use mv to rename file.

pi@raspbmc:~/temp$ ls file1.txt file2.txt file3.txt pi@raspbmc:~/temp$ mv file3.txt not_file3.txt pi@raspbmc:~/temp$ ls file1.txt file2.txt not_file3.txt

Exactly same situation as with cp, remamber to be careful because you can easily overwrite files.

rm (remove) and rmdir (remove directory). To delete a file, use the rm command, to remove directory use rmdir.As simple as that.

pi@raspbmc:~/temp$ ls file1.txt file2.txt file3.txt pi@raspbmc:~/temp$ rm file3.txt pi@raspbmc:~/temp$ ls file1.txt file2.txt

But, if the directory is not empty you have to either empty it or use rm -r as in recursive to delete directory along with all contents.

Downloads nzb.sh nzbget sb.sh script sickbeard temp unrar-nonfree xbmc-backup.tar.gz pi@raspbmc:~$ rm -r temp pi@raspbmc:~$ ls

Downloads nzb.sh nzbget sb.sh script sickbeard unrar-nonfree xbmc-backup.tar.gz

cat (concatenate). The command cat is mostly used to display the contents of a file on the screen.

i@raspbmc:~/temp$ cat text1.txt line 1

line 2

3rd line fourth line pi@raspbmc:~/temp$

And that’s all. I merely scratched surface of this topic, if you feel that we should more advanced linux tutorial let us know in comments.

Was this article helpful?

0 0