Skip to content

Creating and manipulating files in Fedora.

June 16, 2009

The bash shell commands can be used to create files.

To create a file in bash you can use the following command:

$ touch filename

Now run the following command:

$ ls -l filename

You can see that the file contains zero bytes and the date of creation of the file

You can also try running this command:

$ ls -il filename

This will display almost the same information with the inode number of the file.

Copying the contents of files.

To copy the contents of a file you can use the following command:

$ cp source destination

eg: cp file1 file2


To copy file to a existing directory use the command


cp file1 directoryname

To copy file to a directory in your home directory type:

cp file1 directoryname/

To copy file to a directory you are currently in type:

cp /home/dogger/blog/file1 .
cp: overwrite ‘./file1’?

You can use different parameters to manipulate your files and directories too.

cp -R dir1 dir2
recursively copies the contents of one directory to the other.

The different parameters you can use to manipulate files and directories

-a This parameter archives file by preserving its attributes.
-b Creates a backup of the existing file.
-d This attribute preserves the attributes of the existing file.
-f Forces the overwriting of existing destination
-i This command is same is -f, but prompts before overwriting.
-l It is used to create a file link.
-p This attibute is used to preserve the same attributes as that of the orginal file in the copied file.
-r This parameter is used to copy files recursively.
-R Copies the contents of directories recursively.
-v Verbose mode.
-x The file copy is restricted to the current filesystem.

To see the owner of a directory( not root).

ls -dlR */

To see owner with subdirectories and permissions

ls -dl ‘find /var -type d’

To see the owner of folders

ls -dl `find /var -type d` | grep -v root

Moving files

mv filename.txt directoryname

Moving files by specifying absolute path

mv sneakers.txt /home/dogger/filename.txt /home/dogger/directoryname

Removing files

rm -i filename

To display the type of file

file filename

To display the contents of a file

cat filename

You can also use cat to create file use:

cat > filename

Parameters used for cat

-b Display lines with text in numbered format.

-n Numbers each line in the file.

-s convert the blank lines in file into single line.

-T Removes tab and replace it with ^I.

No comments yet

Leave a comment