0% found this document useful (0 votes)
22 views

W COMMAND - Shows Information About The Users Currently On The Machine, and Their Processes

The document contains solutions to various Linux commands related questions. It discusses commands to check logged in users, find current directory, create and list files and folders, set permissions on files and folders, copy, move, rename, delete and remove files and folders, find processes and more.

Uploaded by

Kunal chandoliya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

W COMMAND - Shows Information About The Users Currently On The Machine, and Their Processes

The document contains solutions to various Linux commands related questions. It discusses commands to check logged in users, find current directory, create and list files and folders, set permissions on files and folders, copy, move, rename, delete and remove files and folders, find processes and more.

Uploaded by

Kunal chandoliya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Q1. Write the command to check users are currently login on your system.

Also find how


many users are logged in.
 W COMMAND - Shows information about the users currently on the machine, and their
processes.
 who command – Display information about users who are currently logged in.
 users command – See the login names of the users currently on the system, in sorted order,
space separated, on a single line. It reads all information from /var/run/utmp file.
Q2.Find the present Directory you are working in.
SOL. Determining Your Current Directory with pwd
As you browse directories, it is easy to get lost or forget the name of your current directory. By
default, the Bash prompt in Red Hat Enterprise Linux shows only your current directory, not the entire
path. For example, the path to the application gedit is /usr/bin/gedit. The path to user someone's
home directory is /home/someone/.
Q3. Create a file with contents as a list of all files and folders in your home directory.
Sol.Using the "Touch" Command
Press Ctrl+Alt+T to open the Terminal. The Terminal is a command-line interface that is available on
most Linux distributions. It typically has an icon that resembles a black screen with a white text
cursor. You can either click the Terminal icon in the Apps menu, or press Ctrl + Alt + T at the same
time to open the Terminal.
Q4. Create a directory of your name in your home directory. Create a file in the directory and
given the following permission to it using relative method:
a. rw to user and none to group and others
b. make the file non-editable
c. all permissions to everyone
SOL. 1) chmod 700 folder1
 chmod 400 myfile.txt
 chmod 440 myfile.txt
 chmod 444 myfile.txt
3) chmod ugo+rwx folder1
Q5. Create a file of your name in your home directory. Give the following permissions to it
using relative method using absolute method:
a. rw to user and none to group and others
b. make the file non-editable
c. all permissions to everyone
SOL. 1) chmod 700 folder1
 2) chmod 400 myfile.txt
 chmod 440 myfile.txt
 chmod 444 myfile.txt
3) chmod ugo+rwx folder1
Q6. Create a directory in your home directory with a file in it. Then move the directory to
'Desktop'. Also, rename the file.
Using the "Touch" Command
1) 1 Press Ctrl+Alt+T to open the Terminal.
2) 2 Navigate to the directory you want to create a file in.
3) 3 Type touch.
4) 4 Type the name of the file and press ↵ Enter.
5) 5 Type ls and press ↵ Enter.
6) 6 Move to desktop and Renaming Directories desktop With the mv Command .
Q7. Create a directory and then rename it to "NewFolder".
1) 1 Press Ctrl+Alt+T to open the Terminal.
2) 2 Navigate to the directory you want to create a file in.
3) 3 Type touch.
4) 4 Type the name of the file With "NewFolder" and press ↵ Enter.
5) 5 Type ls and press ↵ Enter.
Q8. Copy multiple files from your folder on Desktop folder named as 'copyfolder'.
Sol.1) The cp command is the primary method for copying files and directories in Linux. Virtually all
Linux distributions can use cp. The basic format of the command is:
cp [additional_option] source_file target_file
For example: cp my_file.txt my_file2.txt
This Linux command creates a copy of the my_file.txt file and renames the new file to my_file2.txt.
2) List each file to be copied before the target directory:
cp my_file.txt my_file2.txt my_file3.txt /Copyfolder
This example created a copy of all three files in the /copyfolder folder.
3) To copy an entire folder and its subfolders and files, use the –R option:
cp –R /documents /copyfolder
–R stands for recursive, which means “everything in that location.” This would copy all the files, as
well as all the directories, to the /copyfolder folder.
Q9. Move multiple files to your folder named as 'movefolder' from 'Desktop'.
Sol.Using mv Command
The mv command is used to move files and directories from one place to another. We can also use it
to rename files and directories.
Let’s see a basic example of how to move all files to the parent directory using the mv command:
mv folder1 folder2 target/ movefolder
Q10. Write the command to jump to your home directory.
Sol.To change directory to home directory, execute the cd command as follows:
cd /home
Q11. Create 'test1' and 'test2' directory and then remove both using a single command.
Sol.- Use the mkdir command to create one or more directories specified by the Directory parameter.
- To create a new directory called Test in the current working directory with default permissions, type
the following:
mkdir Test1 Test2
- To permanently remove a directory in Linux, use either the rmdir or rm command. The rmdir or rm -d
command is for removing empty directories, while the rm -r command deletes non-empty directories.
Before removing a directory, you must know its name.
Rmdir test1 test2
Q12. Remove multiple files through a single command.
Sol.To delete multiple files at once, simply list all of the file names after the “rm” command. File
names should be separated by a space.
rm DeleteMe.odt DeleteMe2.odt
With the command “rm” followed by multiple file names, you can delete multiple files at once.
Q13. Create 6 files with names-file1.txt, file2.txt, file3.cpp, myfile, abc.txt, xyz.c
Write commands to check the files using wildcard characters:
a) List files beginning with "f"
b) List all text files only
c) List all files having the word "file" in their names
d) List a file having 6 characters in its name
e) Count number of files whose names begin with "f"
f) Search for a file with "Hello" as contents.
Sol.The touch command is the most commonly used command for creating a new file in Linux. To
create a new file in the current directory, you need to run the touch command followed by the name of
the file.
$ touch file1.txt file2.txt file3.cpp myfile abc.txt xyz.c
a) ls -d f*
b) This command will list all the .txt files in your current directory and its sub-directories.
find /path/to/search -name "*.txt"
To find .txt files in a particular directory and sub-directory, you can replace the /path/to/search
with the path of your directory.
c) One popular use case for grep is searching for a particular word inside a text file.
To do so, just type the following command:
grep query file
query – the word you’re looking for.
file – the file in which you’re looking for the query.
In our case, we’re looking for the word VPS in the sample file called Hostinger.txt:
grep VPS Hostinger.txt
d) .123456.txt
e) ls -d f*
$ wc ls -d f*
f) grep Hello
Q14. Create a directory having some files in it. Then without removing files individually,
remove the entire directory.
Sol. - Use the mkdir command to create one or more directories specified by the Directory
parameter.
mkdir Test1 Test2
- To permanently remove a directory in Linux, use either the rmdir or rm command. The rmdir or
rm -d command is for removing empty directories, while the rm -r command deletes non-empty
directories.
Rmdir test1 test2
Q15. Display all commands executed today.
Sol.history command is used to view the previously executed command. These commands are
saved in a history file. In Bash shell history command shows the whole list of the command.
Syntax: $ history
Here, the number(termed as event number) preceded before each command depends on the
system. You may get different numbers while executing on your own system.
Q16. Display 3 months consecutive calendar.
cal -3 : Shows calendar of previous, current and next month
Q17. Find the processes running on your system. Close the shell using kill command.
Sol.The ps command is a traditional Linux command to lists running processes. The following
command shows all processes running on your Linux based server or system:
$ ps -e
Once the shell returns the list, you can press k to kill the process.
Q18. Print today's date.
Sol.To print this date either use the echo statement:
$ echo "Current date: $now"
Q19. Create a file with 10 lines. Display the first 5 lines and last 3 lines of the file.
1) Firstly, create file (file10) which contain 10 lines , by using touch command :
$ touch File10.txt
2) Type the following head command to display first 5 lines of a file named “bar.txt”:
head -5 File10.txt
3) To display the last 3 lines of the notes file, type the following:
tail - 3 File10.txt
Q20. Create a file on desktop.
1. Copy file to 'Desktop' with a different name
2. Copy from your home directory to 'Desktop' with a different name
3. Create another folder on 'Desktop' and copy to it
Sol.1. cp program3.cpp homework6.cpp
2. cp <home_file> <~/desktop>
3. TOUCH [file1]
cp <file1> <~/desktop>

You might also like