Sparkles

that were shone when I got tempered!

Bash Scripts for dealing with files/folders

leave a comment »

Make Files

Create a log file using cat command :


cat > /filepath/fileName.ext [ENTER]

testText1

testText2

---

Enter CTRL+C to exit from cat.

Make directories

Create a directory :

mkdir dirname

Create multiple directories

mkdir dirname1 dirname2 dirname3

Create directory with Parents

mkdir -p dir1/dir2/dir3

Create directory with a Message

mkdir -v dirname1 dirname2 dirname3

Delete Directories

Delete an empty directory :

rmdir dirName

Delete an empty directory :

rmdir dirName

Delete empty directories :

rmdir dirName1 dirName2

Delete a non-empty directory with sub-folders and contents (recursive removal) :

rm -rf /path/to/directoryOrFile

Delete all components in the directory path name (if they are empty – starting from last most component) :

rmdir -p /tmp/x/y/z

If you encounter an issue with deleting the directory / file, check the permission of the parent directory. I got some files saying “Permission cannot be determined” notification. But it disappeared when I gave chmod 777 to parent directory.

Copy / Cut – Paste

Copy and Paste – Asking you if you want to replace the file – interactive

rmdir -p /tmp/x/y/z

Copy and Paste – Creating a backup of your file

cp -b /home/levan/kdenlive/untitelds.mpg /media/sda3/SkyDrive

Copy and Paste – a directory with it’s content

cp -Ri ~/MyFolder /sda3/

Cut and Paste a file

mv -i ~/MyFile ~/OtherFolder/MyFile

Cut and Paste – a directory with it’s content

mv -Ri ~/MyDirectory ~/OtherDirectory/

 

 

Reference :

Advertisements

Written by Namal Fernando

September 25, 2013 at 10:47 am

Posted in Linux

Tagged with ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Ruth's Reflections

Contemplations from quakey quirky Christchurch

TED Blog

The TED Blog shares interesting news about TED, TED Talks video, the TED Prize and more.

Ziplok

Learn and discover simple things

Meihta Dwiguna Saputra's Knowledge Base

~In learning you will teach and in teaching you will (re)learn~

The Java Blog

Thoughts, tips and tricks about the Java programming language

Sparkles

that were shone when I got tempered!

%d bloggers like this: