The document discusses several ways to create, find, list, and move files in Linux. It provides examples of using touch, redirection, cat, dd, and fallocate commands to create empty or populated files. The find command can be used to search for files by name or type, and getent passwd lists users and checks if a user exists. The mv command moves files between locations with optional backup of conflicting files.
The document discusses several ways to create, find, list, and move files in Linux. It provides examples of using touch, redirection, cat, dd, and fallocate commands to create empty or populated files. The find command can be used to search for files by name or type, and getent passwd lists users and checks if a user exists. The mv command moves files between locations with optional backup of conflicting files.
The document discusses several ways to create, find, list, and move files in Linux. It provides examples of using touch, redirection, cat, dd, and fallocate commands to create empty or populated files. The find command can be used to search for files by name or type, and getent passwd lists users and checks if a user exists. The mv command moves files between locations with optional backup of conflicting files.
-The touch command allows us to update the timestamps on existing files and directories as well as creating new, empty files: EX: $ touch file1.txt -To create multiple files at once, specify the file names separated by space: EX: $ touch file1.txt file2.txt file3.txt
2 Creating a File with the Redirection Operator
-To create an empty zero-length file simply specify the name of the file you want to create after the redirection operator: EX: $ > file1.txt 3 Creating a File with cat Command -To create a new file run the echo command followed by the text you want to print and use the redirection operator > to write the output to the file you want to create: EX: $ echo "Some line" > file1.txt -To create an empty simply use:
EX: $ echo > file1.txt
4 Using dd command -The dd command is primarily used to convert and copy files: EX: To create a file named 1G.test with a size of 1GB you would run: $ dd if=/dev/zero of=1G.test bs=1 count=0 seek=1G 5 Using fallocate command -fallocate a command-line utility for allocating real disk space for files: EX: command will create a new file named 1G.test with a size of 1GB: $ fallocate -l 1G 1G.test
Linux search file:
1 If you need to know how to find a file in Linux called thisfile. EX: find . - name thisfile.txt 2 Look for all . jpg files in the /home and directories below it. EX: find /home -name *.jpg. 3 Look for an empty file inside the current directory. EX: find . - type f -empty
Linux list users:
1 Get a List of All Users using the /etc/passwd File -Local user information is stored in the /etc/passwd file. Each line in this file represents login information for one user. To open the file you can either use cat or less : EX: $ less /etc/passwd -To display only the username you can use either awk or cut commands to print only the first field containing the username: EX: $ awk -F: '{ print $1}' /etc/passwd $ cut -d: -f1 /etc/passwd 2 Get a List of all Users using the getent Command -To get a list of all Linux userr, enter the following command: EX: $ getent passwd 3 Check whether a user exists in the Linux system -To check whether a user exists in our Linux box we, can simply filter the users' list by piping the list to the grep command. EX: To find out if a user with name jack exists in our Linux system we can use the following command: $ getent passwd | grep jack - To find out how many users accounts you have on your system, pipe the getent passwd output to the wc command: EX: $ getent passwd | wc -l 4 Symtem and Normal Users -To check the UID_MIN and UID_MIN values on your system, you can use the following command: EX: $ grep -E '^UID_MIN|^UID_MAX' /etc/login.defs
Linux move life:
1 Moving with a mouse Holding the Shift key while dragging a file forces a move action. 2 Moving on the command line A simple command with a predictable syntax, mv <source> <destination> moves a source file to the specified destination, each defined by either an absolute or relative file path. 3 Moving a file -To move a file from one folder to another with mv, remember the syntax mv <source> <destination>. For instance EX: To move the file example.txt into your Documents directory: $ touch example.txt $ mv example.txt ~/Documents $ ls ~/Documents example.txt 4 Moving with backups -To create a backup of any conflicting destination file, use the -b option: EX: $ mv -b example.txt ~/Documents $ ls ~/Documents example.txt example.txt~