WILDCARDS IN LINUX:
wildcards in Linux are special characters that represent patterns and help you perform operations on multiple files or directories at once. They allow you to match a variety of filenames based on a specific pattern or criteria. Wildcards are typically used with commands like ls
, cp
, mv
, and rm
to work with groups of files that share a common characteristic.
Here are a few Linux wildcards that are often used:
Asterisk (*): It can be used to represent any character, even none. For instance, the command ls *.txt lists all files in the current directory that have the ".txt" extension.
Question mark (?): A single character is represented by the question mark (?). For instance, "file1.txt" and "file2.txt" will be listed by $ ls file?.txt, but "file10.txt" won't.
Square brackets ([]): It matches any single character included between the square brackets ([]). Files like "file1.txt," "file2.txt," or "file3.txt" will be listed, for instance, by the command $ ls file[123].txt.
Curly braces (): You can provide numerous choices using commas to separate them. To copy both "file1.txt" and "file2.txt" to the "destination" directory, use the command "cp file1,file2.txt destination/".
CREATING FILES AND DIRECTORIES:
COMPARISON OF CREATING DIRECTORIES BETWEEN WINDOWS AND LINUX
COMPARISON OF CREATING FILES BETWEEN WINDOWS AND LINUX:
FILES AND DIRECTORIES PERMISSION in LINUX:
Permissions on Linux files and directories control who may access them and what operations can be carried out on them. Three sets of characters are Owner, Group, and Others, stand in for permissions. An overview of Linux file and directory permissions is provided below:
File Access Rights:
Read (r): This function enables reading or seeing the file's content.
Write (w): Permits editing the file's content.
Execute (x): Allows running the file, whether it is a programme or a script. Permissions for the directory
Directory Access Rights:
Read (r): Allows listing the directory's contents.
Write (w): This command enables the creation, deletion, and renaming of files and directories inside a directory.
Execute (x): Permits entry and access to the directory.
There are a few exceptional characters as well:
-(dash): Shows that a certain permission is not given.
d(directory): Indicates the directories
l (link): Signifies a symbolic link.
t (sticky bit): A special permission for directories that only allows the owners of the files to delete them.
When you view the permissions of a file or directory using the $ls -l
command, you'll see something like this:
-rw-r--r-- 1 owner group 4011 Jun 12 10:00 myfile.txt
drwxr-xr-x 2 owner group 4096 Jun 12 10:00 mydirectory
Thee above example, rw-r--r--
represents the file permissions, and $drwxr-xr-x
represents the directory permissions.
To modify the permissions, you can use the chmod
command in Linux. For example, to give read and write permissions to the owner of a file, you can use:
chmod u+rw file1.txt
PERMISSION USING NUMERIC MODE:
FILE OWNERSHIP COMMANDS
chown: Changes the ownership of a file or directory.
$ chown <new_owner> <file_name>
chgrp: Changes the group ownership of a file or directory.
$ chgrp <new_group> <file_name>
chmod: Changes the permissions of a file or directory. Permissions control the read, write, and execute access for the owner, group, and others.
$ chmod <permissions> <file_name>
Here,
<permissions>
can be represented in various ways:Numeric form: Each permission is assigned a number (read = 4, write = 2, execute = 1), and the sum of these numbers represents the desired permission. For example, 755 gives read, write, and execute permissions to the owner (7 = 4 + 2 + 1), and read and execute permissions to the group and others (5 = 4 + 1).
Symbolic form: Uses letters to represent permissions. The letters are "r" for read, "w" for write, and "x" for execute. Additionally, "u" represents the owner, "g" represents the group, and "o" represents others. For example, "u=rw,g=r,o=r" gives read and write permissions to the owner, and read permissions to the group and others.
chown/chgrp -R: Recursively changes ownership/group ownership of a directory and its contents.
$ chown -R <new_owner> <directory_name> $ chgrp -R <new_group> <directory_name>
These commands require appropriate permissions to modify ownership. Generally, only the superuser (root) or the current owner of a file can change ownership.