Print the first N bytes of a file in Linux
Answer:
To print the first N bytes of a file in Linux, you can try the following method:
# head --byte 4 input.txt
...
The above command print the first 4 bytes of the file input.txt
Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.
Print the first N bytes of a file in Linux
Answer:
To print the first N bytes of a file in Linux, you can try the following method:
# head --byte 4 input.txt
...
The above command print the first 4 bytes of the file input.txt
Count the total number of logged in user
Answer:
To count the total number of logged in user(s), use the following commands:
# who | wc -l
3
It shows currently there are 3 users logged in.
Add a user to group in Linux
Answer:
To add a user to a group (supplementary), you can use the command below:
e.g.
# useradd -G admin john
If you want to change the user's primary group, you can use
e.g.
# useradd -g admin john
Add a User in Linux
Answer:
Add a User in Linux, just use the useradd command:
# sudo useradd -d /home/john -m john
The above command will create the user john and create a home directory which is at /home/john
Make a file executable in Linux
Answer:
Assume you have create a shell script, my.sh, you need to make this file executable, you can use the chmod command.
# chmod +x my.sh
Then you can execute the script directly
# ./my.sh