Creating
files in UNIX/LINUX
There are different
ways to creating a files two of those i.e touch
and Cat
1.Touch filename
2.cat filename
3.cat >> filename
4.>filename
5.Using vi editor
1)
$touch filename –it creates zero byte file size
Note:
Touch do not allow you to store anything at the time of creation. It is used to
crate several empty files quickly.

Eg:
$touch sample
The size
of the sample file is ZERO bytes.

Eg:
$touch s1,s2,s3
1)
$cat
> filename – which also used to create the files but u
need to follow the CTRL+D to save the file
Eg:
$cat>sample
---------------
---------------
---------------
CNTRL+D(to
save and close a file)
For
execution: $./filename
a)
Cat>>file
name –to append the data into the file
b)
Cat file1 file2 file 3> file 4
It would create file 4 along the contents of data of file 1, file2, file 3
a) Cat<file name (or) cat filename – to view a file
It would create file 4 along the contents of data of file 1, file2, file 3
a) Cat<file name (or) cat filename – to view a file
Removing the files:
$rm <option> filename –which is
used to remove the files.
OPTIONS
Remove (unlink) the FILE(s).
-d, --directory
unlink FILE, even if it
is a non-empty directory (super-user only)
-f, --force
ignore nonexistent files,
never prompt
-i, --interactive
prompt before any removal
-r, -R, --recursive
remove the contents of
directories recursively
-v, --verbose
explain what is being
done
--help
display this help and
exit
--version
output version
information and exit
To remove a file whose
name starts with a `-', for example `-foo', use one of these commands:
rm -- -foo
rm ./-foo
Note that if
you use rm to remove a file, it is usually possible to recover the contents of
that file. If you want more assurance that the contents are truly
unrecoverable, consider using shred.
Note:
$rm * - it removes
all file and directories in the current directory. While using this one try to
check yourself.
$cp oldfile newfile
wc command counts the characters, words or lines in a file depending upon the option.
Creating
and removing a directory
$mkdir dirname–
which is user to create the directories and sub directories.
$mkdir –p
dir1/dir2- Here we
are creating the sub directory dir2 in dir1.
rmdir command will remove
directory or directories if a directory is empty.
Options:
- rm -r directory_name will remove all
files even if directory is not empty.
- rmdir chinnu is how you use it to
remove chinnu directory.
- rmdir -p will remove directories and
any parent directories that are empty.
- rmdir -s will suppress standard error
messages caused by -p.
cp
command copies a file. If I want to copy a file named old file in a current
directory to a file named newfile in a current directory.
$cp oldfile newfile
If
I want to copy oldfile to other
directory for example /tmp then
$cp
oldfile /tmp/newfile.
Useful
options available with cp are -p
and -r . -p options preserves
the modification time and permissions, -r recursively copy a directory and its
files, duplicating the tree structure.
Wc command
wc command counts the characters, words or lines in a file depending upon the option.
Options
- wc -l filename will print total
number of lines in a file.
- wc -w filename will print total number of words
in a file.
- wc -c filename will print total
number of characters in a file.
- Listing of files:The ls command lists all files in the directory that match the name. If name is left blank, it will list all of the files in the directory.The syntax for the ls command is:ls [options] [names]Options:-aDisplays all files.-bDisplays nonprinting characters in octal.-cDisplays files by file timestamp.-CDisplays files in a columnar format (default)-dDisplays only directories.-fInterprets each name as a directory, not a file.-FFlags filenames.-gDisplays the long format listing, but exclude the owner name.-iDisplays the inode for each file.-lDisplays the long format listing.-LDisplays the file or directory referenced by a symbolic link.-mDisplays the names as a comma-separated list.-nDisplays the long format listing, with GID and UID numbers.-oDisplays the long format listing, but excludes group name.-pDisplays directories with /-qDisplays all nonprinting characters as ?-rDisplays files in reverse order.-RDisplays subdirectories as well.-tDisplays newest files first. (based on timestamp)-uDisplays files by the file access time.-xDisplays files as rows across the screen.-1Displays each entry on a line.Examples:ls -la
No comments:
Post a Comment