Moving Around

command options(s) filename(s)

$ echo -e 'Hello, world!

'

cd /

$ ls bin dev home media proc selinux tmp vmlinuz boot etc lib mnt root srv usr initrd.img cdrom floyd lost+found opt sbin sys var

$ ls / bin dev home media proc selinux tmp vmlinuz boot etc lib mnt root srv usr initrd.img cdrom floyd lost+found opt sbin sys var

$ cd /home/your_username/

debian$ echo $USER embryo

$ pwd /home/embryo/

$ ls Downloads Music my_stuff textfile

$ ls -lha total 20K drwxr-xr-x 2 embryo embryo 4.0K 2010-12-19 15:12 Downloads drwxr-xr-x 2 embryo embryo 4.0K 2010-12-19 15:12 Music drwxr-xr-x 2 embryo embryo 4.0K 2010-12-19 15:21 my_stuff -rw-r--r-- 1 embryo embryo 0 2010-12-19 15:21 textfile drwxr-xr-x 5 embryo embryo 4.0K 2010-12-19 15:32 . drwxr-xr-x 62 embryo embryo 4.0K 2010-12-19 15:12 .. -rw-r--r-- 1 embryo embryo 0 2010-12-19 15:32 .bashrc

$ cd /home/embryo/Downloads

$ cd embryo/Downloads

cd ../../

debian$ mkdir myfolder

debian$ ls Downloads Music myfolder my_stuff textfile

$ mkdir docs

$ touch emptyfile

$ rm emptyfile

$ rm -r docs

mkdir newdir touch newfile

$ cp newfile newdir

$ cp /home/embryo/myfolder/newfile /home/embryo/myfolder/newdir/

touch file2 mv file2 newdir

$ touch mynewfile $ ls mynewfile newdir newfile $ mv mynewfile file3 debian$ ls file3 newdir newfile

$ cd newdir/ $ ls newfile $ mv newfile ../renamed_file $ cd .. $ ls file3 newdir newfile renamed_file

debian$ date Sun Dec 19 16:06:53 EET 2010

$ date +"%H:%M:%S" 16:09:52

debian$ cal December 2010 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

$ whoami embryo

$ uname -a Linux debian 2.6.26-2-686 #1 SMP Thu Nov 25 01:53:57 UTC 2010 i686 GNU/Linux

$ who embryo :0 2010-12-19 07:55

$ uptime 20:10:31 up 12:15, 1 user, load average: 0.02, 0.02, 0.00

$ echo 'Hello, world!' Hello, world!

$ whereis bash bash: /bin/bash /etc/bash.bashrc /usr/share/man/man1/bash.1.gz

$ which wesnoth /home/embryo/usr/bin/wesnoth

Linux commands are executable binary files which can be ran to perform certain tasks, like for example listing the files in a directory running an entire graphical application. Examples of frequently used commands areor. With the exception of executable files, there is also a category called shell built-ins, which are commands provided by the shell itself (Bash in our case). We'll deal with those later.The general form of a Linux command is:Which specifies a command, followed by one or more parameters, and optionally one or more files to apply it on. For example:Will output the text 'Hello, world!' followed by a newline character. Theparameter (also called argument, or switch in this case) tells the echo command to interpret escaped characters, like the trailing, which will add a newline after the text inside the single quotes. Ignore the leading dollar sign, it just signifies the shell prompt.A command may or may not have arguments. An argument can be an option or a filename.Usually when you start a terminal the default starting location (called the) is your home folder,. Let's say we want to move to the root directory. We will issue the following command:As you can see, we used thehangeirectory) command, followed by a single argument, the path where we want to go (the root directory is represented by the slash sign). Now let's vizualize the contents of the root directory using thecommand:These are all files and directories located in our root folder. If we would've wanted to list the contents of this folder directly from where we were, in the home folder, we would've calledwith a single argument, the slash sign:And it would've had the same result.Now let's go back inside our home directory and list its contents. To do this, we have two options:without any parameters always changes the working directory to the home of the current user (unless it is aliased). Alternately, you could type:And you should be back in your home folder. Don't forget to replace. If you don't know what your username is type. On my computer this would output 'embryo', which is the user I'm currently logged in with:Now let's see what the current working directory is. We will use therintorkingirectory) command to do so:Now let's see the contents of our home directory using thecommand. It should output something like the following (yours may vary):There is more tothough. Let's say we want to also list hidden files and show detailed information about each separate file. For this we will group several switches and pass them to ls:We grouped three different switches and passed them to ls: theswitch tells ls to use the long listing format (with detailed information about each separate file), theswitch tells ls to show file sizes in a human-readable format (kilobytes, megabytes or gigabytes where is the case instead of bytes) and finally, theswitch tells ls to also show the hidden files (the ones that start with a dot - in our caseand). You will have more in your home directory.Regarding the dot and double dot: these are also files, in that they are virtually meaning the current directory and the parent directory, respectively. So,will list the contents of the parent directory, which in our case iswill list the contents of the current directory just likewithout arguments does. Bash uses expansion to replace these with their actual meaning. So issuingis read by Bash exactly like you would type, since /home/ is the parent directory relative to what the current working directory is.Anis a complete path, and it always starts with the root directory (slash sign)., these are all absolute paths. They specify the complete path up to a certain point.On the other hand, awill always take into consideration the current working directory. So if you are, say, in the directoryand you want to change to, say,you could do it like this:In this example we specified the full path to the Downloads directory, or the absolute path. Notice the leading / sign for root. To do it using a relative path we would issue this command:Notice that we only specify the path from where we are, and there is no leading slash sign.Go back to your home folder (use) and let's see how the double dot works. As I already mentioned, the double dot means the parent directory of the directory we're currently in. So let's say we want to go to the root directory again, but this time using double dot. Here's the command:Which tells cd to go up to the parent directory, and then go up in the tree hierarchy one more time. You should be in the root directory now (check with). The trailing slash in the above command is not necessary.Now let's focus on performing simple tasks like creating directories, view date and time, or simply playing around with some more basic commands.To create a new directory, we will use the(make directory) command. First, make sure you are in your home directory with. If not, typeto get there. Now, let's create a new directory:We created a new directory called. If you list your files now, your new folder should appear:Now let's go inside our newly created folder, only this time using. The tilda sign signifies your home directory, and it expands into /home/your_username/. So issuingis the same as issuing. Now let's create another folder, calledNow let's create an empty file using thecommand:Thecommand creates an empty file with the name of its argument if that file doesn't already exist, or it updates the last modification date and time if it exists. Now since we created an empty folder and an empty file, let's see how we can delete them.To remove files or folders, we will use thecommand. To remove our newly created file type:And to remove thedirectory:Notice that to remove a directory we need the -r switch.Let's go back insideand create a new directory and a new file:Now let's use thecommand to copy the file newfile inside the directory newdir:This is the same as if we would've typed the following:But in our first example we used a relative path.Now let's create another file inside myfolder, and then move it to newdir:We used thecommand to move it. Now let's create a new file inside myfolder, and rename it. Notice that in Linux renaming is accomplished using thecommand, they are one and the same thing. Let's create a file calledand rename it to(we will list the contents of the directory after each step to see the changes):Now let's go inside thedirectory, and use the double dot to move file2 from there inside myfolder, and also rename it (we will list the contents after each step to reflect the changes):So first we entered in newdir. The filewas there since we moved it earlier. Next, we moved it to the parent directory, but with a changed name,. Next, we changed the working directory to the parent of newdir and we listed its contents. As a side note, if you copy or move a file and the new destination name is the name of a directory, the file will be moved inside that directory.To view the current system's date and time, we will use thecommand:Notice that date can be invoked in various ways in order to format the output. For example, to show only the time in an HH:MM:SS format (hour, minute, second) we would use:Theparameter formats the output of the date command. Another useful command is, which will show a calendar:You can try thecommand, which will show your username:The commandis used to print system information. In combination with the(all) switch, it will print various information including hostname, kernel version, date and operating system:Thecommand is used to show is logged on, the number of the tty (teletype terminal) or display they are using, and the date and time they logged in:Another useful command is, which will show for how long the system has been running:To print a line of text to the screen we'll use thecommand:In order to see the path in which a command is located we will use thecommand, which will search in all the standard locations:Notice thatwill not look into non-standard paths. Instead, we can use thecommand for that: