File Handling In Shell



Objective:
·         Learn how to work with Linux File
·         Learn about copy and check directory
·         Learn about file handling

Introduction:
Linux organises it's file system in a hierarchical way. Over time you'll tend to build up a fair amount of data (storage capacities are always increasing). It's important that we create a directory structure that will help us organise that data in a manageable way. I've seen way too many people just dump everything directly at the base of their home directory and waste a lot of their time trying to find what they are after amongst 100's (or even 1000's) of other files. Develop the habit of organising your stuff into an elegant file structure now and you will thank yourself for years to come.

mkdir [options] <Directory>
  • Line 1: Let's start off by making sure we are where we think we should be. (In the example above I am in my home directory)
  • Lines 2: We'll do a quick listing so we know what is already in our directory.
  • Line 7: Run the command mkdir and create a directory linuxtutorialwork (a nice place to put further work we do relating to this tutorial just to keep it separate from our other stuff).




TRY:
mkdir /home/ryan/foo
mkdir ./blah
mkdir ../dir1
mkdir ~/linuxtutorialwork/dir2

And now the same command but with the -v option

Creating a Blank File
A lot of commands that involve manipulating data within a file have the nice feature that they will create a file automatically if we refer to it and it does not exist. In fact we can make use of this very characteristic to create blank files using the command touch.
touch [options] <filename>

Q1: Write a command that make .doc file extension in your PWD?
Q2: Write a command to make .sh file extension in ~PWD?
Copying a File or Directory
There are many reasons why we may want to make a duplicate of a file or directory. Often before changing something, we may wish to create a duplicate so that if something goes wrong we can easily revert back to the original. The command we use for this is cp which stands for copy.
cp [options] <source> <destination>

Q3: Explore -r option while copying in to PWD?

Post a Comment

0 Comments