Skip to main content

Directories and files

In this blog, we will try to understand some of the useful commands in Ubuntu operating system.( or any other linux system). All the commands we discuss are terminal command. Because if we just wanted to work on GUI, we would have stayed back in Windows. Right.

To start a terminal on your screen, give CTRL+ALT+t

Starting and stopping Ubuntu system


We know how to start the computer and login. But how do we stop the system?

There are 3 text based commands for this operation viz halt, shutdown and reboot.

halt    - will shutdown the computer
reboot - will shutdown the computer and restart
shutdown - has many options
    shutdown -h now will shutdown
    shutdown -r now   will restart
    shutdown   +10  "shutting down the system in 10"
will display the message given and shutdown the system after 10 minutes 

Directories and files

Directory - is nothing but a folder in windows terminology. It is a place where you store your files. And it has a name.

Remember that whether file name or directory name, it is case sensitive. So myfiles is different from MyFiles, and also different from MYFILES.

All linux based systems create a home directory for you, when your user is created. The directory organization is something like this in Ubuntu (and in other linux systems)
Image from: http://researchhubs.com
So for you as the user, your home directory path will be /home/yourname. As soon as you login by providing your password, you will enter this directory.

Within this directory you can create sub-directories and files. The command used for creating a directory is

    mkdir name
    mkdir absolute-name

Absolute name must contain the complete path such as /home/yourname/cprograms.

cd command

cd is a command for changing directory. 

cd /home/usha/cprograms
    go to a directory /home/usha/cprograms

cd /home/tom/androidprojects
   go to a directory /home/tom/androidprojects

cd cpp
  go to the sub directory cpp. i.e. from the current directory go to child directory cpp.

To know what is your current directory you can give command

pwd

Special characters in file path

We can use the following special characters when specifying the path of a file/directory.

. - current directory
.. - parent directory
~ - home directory

home directory always means user's home directory. In my case it is /home/usha.

cd without any arguments will always goes to home directory.

List of files in a directory 

If you want to list the files and sub-directories in any directory, you can use ls command.  (ls is similar to dir in windows OS).

ls

You may not see any output now. If you are new to the machine and you have not created anything, there are no files are directories to start with. 

Let us create a dummy file using a notepad kind of GUI editor called gedit. 

Type gedit, type some content into the file and save the file giving a name, say a.txt

Now ls command will show you 

a.txt

cat command 

cat command can be used for concatenating two files. But here let us see its use just for displaying the contents of a file.



Or whatever else you have typed in a.txt file will be displayed.

Hidden files

Let me just do one trick now

mv a.txt .a.txt
ls

Now the file a.txt has disappeared 

What happened? Did the file a.txt got deleted?

No. It is just hidden.

How? By renaming it as .a.txt. 

In Linux any file(or directory) whose name starts with . will be hidden. And it will not be displayed when we use ls command.

Unless....

Unless we use the option -a with ls. -a indicates all. 

Let us give ls -a now.

 There are extra files appearing here - .bashrc, .bash_logout etc. These are all system created files. We will talk about them later.

Comments