Linus Commands

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Linux Commands

Basic Linus Commands:


Creating a File (cat filename)
Copying a File (cp firstfile secondfile)
Renaming a File:
Linux does not have a command specifically for renaming files. Instead, the mv command is
used both to change the name of a file and to move a file into a different directory.
To change the name of a file, use the following command format (where thirdfile and file3 are
sample file names):
(mv thirdfile file3)
Removing a File:
Use the rm command to remove a file. For example,
(rm file3)
Creating a Directory:
(mkdir project1)
Moving and Copying Files Into a Directory:
The mv and cp commands can be used to put files into a directory. Assume that you want to
place some files from your current directory into a newly created directory called project1. The
command
(mv bibliography project1)
will move the file bibliography into the directory project1. The command
(cp chapter1 project1)
Lab 5

Q1

a. Use cd to go to your home directory, and create a new directory there

called dog.

b. Create another directory within that one called cat, and another within that called

mouse.

c. Remove all three directories. You can either remove them one at a time, or all at

once.

d. If you can delete directories with rm -r, what is the point of using rmdir for empty

directories?

 The rm -r command can remove directories and their contents recursively, even if they are not
empty.
 mdir is specifically use to remove empty directories only. So, the point of using rmdir for empty
directories is to ensure that you don't accidentally delete directories that contain files.
e. Try creating the dog/cat/mouse directory structure with a single command.

Q2

a. Copy the file /etc/passwd to your home directory, and then use cat to see what’s in it.
b. Rename it to users using the mv command.

c. Make a directory called programs and copy everything from /bin into it.

d. Delete all the files in the programs directory.

e. Delete the empty programs directory and the users file.

Q3
a. The touch command can be used to create new empty files. Try that now, picking a
name for the new
file:
$ touch baked-beans
b. Get details about the file using the ls command: $ ls -l
baked-beans

c. Wait for a minute, and then try the previous two steps again, and see what changes.
What happens when we don’t specify a time to touch?

Conclusion:
 If you wait for a minute and then try the ls -l command again without re-executing the
touch command, you'll notice that the "baked-beans" file's last modification time (mtime)
will be updated to reflect the time when you last executed the ls -l command. This is
because the act of listing the file's details (ls -l) updates its access time (atime).
d. Try setting the timestamp on the file to a value in the future.

e. When you’re finished with it, delete the file.

You might also like