Monday, March 11, 2019

Part – 3 (Reading File)
Q) How to read or see the content of the file ?
Ans - $ cat <File Name><Enter – Key>
Example - $ cat f1

Copy: -
Q) How to copy the content of a file f1 to a file f2 ?
Ans - $ cp  f1 f2<Enter – Key>
Here two cases arise.
1. if f2 file will not exist, then a new file f2 will be created and it will contain the content of f1.
2. if f2 file will exist, then the content of file f2 will be overwrite by file f1.
Q) How to copy a file f1 to a file f2 which is not opening ?
Ans - $ cp –f f1 f2<Enter – Key>
Where f – forcefully
Q) How to copy a file f1 to a file f2 with asking for confirmation ?
Ans - $ cp –i f1 f2<Enter – Key>
Where i – interactively
Q) How to copy the structure and content of a directory d1 to a directory ~/d5 ?
Note – you are at directory d1.
Ans - $ cp –R d1 ~/d5<Enter – Key>
Q) How to copy a file f1 to a file f2 by keeping modification time, access time, other properties etc
same as f1 ?
Ans - $ cp –P f1 f2<Enter – Key>

Move: - (Rename)
Q) How to rename a file f1 to a file f2 where both files are exist in same folder ?
Ans - $ mv f1 f2<Enter – Key>
After Move Operation,
1. f1 file will not exist.
2. f2 will contain the content of f1 with same file name f2.
Q) How to move files f1, f2 and f3 to a folder ~/d2/hir/dir5
Note – f1 file present in your current folder.
File f2 present in ~/d2/d3 folder.
File f3 present in ~/d1 folder.
Ans - $ mv f1 ~/d2/d3/f2 ~/d1/f3 ~/d2/hir/dir5<Enter – Key>
Q) How to move a file f1 to a file f2 which is not opening ?
Ans - $ mv –f f1 f2<Enter – Key>
Where f – forcefully
Q) How to move a file f1 to a file f2 with asking for confirmation ?
Ans - $ mv –i f1 f2<Enter – Key>
Where i – interactively
Q) How to move the structure and content of a directory d1 to a directory ~/d5 ?
Note – you are at directory d1.
Ans - $ mv –R d1 ~/d5<Enter – Key>

No comments:

Post a Comment

Interview Questions: - (UNIX - 0) UNIX: -   Q) How to get inode number of a file/directory? Ans – $ ls –i <File/Directory_Name...