07. LINUX commands(6) - Uchiha3000/LINUX_docx GitHub Wiki
LINUX commands part 6
How to know my hostname of any server?
code: hostname
How to redirect or copy the contents of two files f1 and f2 into a third file f3?
code: cat f1 f2 > f3
[Note: First create the first two files and write in them, then execute the command.]
How many lines are there in f04?
code: wc -l f04
How to change the ownership of a file?
code: chown John:sha f3
[Note: The owner of a file is oracle and group user of that file is oinstall. If I want to change the ownership of a file from oracle to John.
Step 1: Check the group user of John by id John.
Step 2: code: chown John:sha f3
OR
We can change the ownership by using the super user or root user.
code: sudo chown John:sha f3
OR
Step 1: Shift your user from oracle to root. code: su - root
Step 2: Enter it's password. (Root's password will be root)
Step 3: Now change the ownership. code: chown john:sha /home/oracle/f3
How to change the ownership of a directory?
code: chown -R John:sha D01
[Note: Maybe just giving the code won't work, so try using the third method in the previous question i.e. changing to root user and then trying to change the ownership of directory.]
Writing our first program in LINUX
Step 1: Create a file named dummy using vi dummy command.
Step 2: The editor of dummy file will be opened. Go to insert mode by esc+i command.
Step 3: Then type the list of commands like this in the editor.
Step 4: Now save, quit and exit by esc+:wq command
Step 5: Before executing the file, check for permission and give the execute permission to the files owner by chmod 755 dummy.
Step 6: Now execute the file using ./filename command (./dummy).
How to find the ip address of my server in LINUX?
code: ifconfig
(doubt)
Create a file to execute the following commands
- Create a directory
- Redirect a month of the calendar to the file created within the said directory
- Long list the contents of the directory
- Show the contents of the file
Ans: Below images contain both the code and its output.
How to take input in a variable and print it?
To take input
code: x=321
To get output
code: echo "x=$x"
How to save a directory location inside a variable?
code: x="/home/oracle/Akash"
How to take input from user and print it.
To take input from user
code: read x
To take output from user
code: echo "Hi I am $x"
Go to the saved location
code: cd "$x"
Create a automation or program to do the following.
- Take a name from user to create a directory
- Take a name from user to create a sub file for the same directory
- Redirect a months calendar to the file
- Long list the contents of the directory
- Show the contents of the file
code:
OUTPUT:
Create a file that asks the user's name and hometown and prints them.
code:
[Note: Remember to change your owner permission to read, write and execute]
OUTPUT:
Make a automation or program in LINUX for addition
code:
OUTPUT:
[Note: When performing mathematical operations we do it in double brackets "(())"]