Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

touch cat vi differences

What are differences between
touch cat vi differences

which one is better to use to create a file. When to use which one. please advise
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gudii9

ASKER

Use vi to edit an existing file or to create a new, empty one and edit it immediately.

Use cat to create a new file from an existing one or to concatenate two or more files to a new one, or to append two or more files to an existing one.

Use touch to create a new, empty file or to update the last modified date of an existing file.

cat and touch does same things?
Please re-read my answer!
cat and touch  c a n  do the same (if you "cat" an empty file into a new one an empty file is created), but cat isn't really meant for this (see above).
touch, on the other hand, never writes content to a file, it changes its date (and creates it, if not present).
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>> Also always use full path.
Here goes exceptions because of not using full path.

Initially doing unalias for ls command and redirecting the error (if any) to /dev/null
$ unalias ls 2>/dev/null

Open in new window

Writing a sample function for ls:
$ unset -f ls
$ ls ()
{
           echo "Use full path instead of using ls command"
           echo "/bin/ls $@"
           Ret=13
           return $Ret
}
$ ls /home/MurugesanDinesh
Use full path instead of using ls command
/bin/ls /home/MurugesanDinesh
$ echo "Return value of previous ls command is [ $? ] which needs to be 13 since we have written 13 in ls function"
Return value of previous ls command is [ 13 ] which needs to be 13 since we have written 13 in ls function
$ echo "Return value of previous echo command is [ $? ] which needs to be 0 since we have used expected output of echo command"
Return value of previous echo command is [ 0 ] which needs to be 0 since we have used expected output of echo command

Open in new window