Commands Learnt Today
Read to the End there’s a Bonus Knowledge below that I also learn about
NOTICE!!! Please do the practice as you read along more than one time to have
it stick
Cal - for calendar
cal month year
Example:
cal 6 2024
Displaying a Full Year
To display a calendar for a full year:
cal -y year
Example:
cal -y 2024
Options that can be used with the Cal command
1. -3 : Display the previous, current, and next month.
2. -j : Display Julian dates (days of the year). => this is referred to as a continues counting of
days from a starting point(day)
3. -m : Specify the month (1-12). => in the case you want to use the month in words you will
need to specify the –m followed by the year e.g. Cal –m January 2025
Date -for date
Customizing the Output
To display the date and time in a specific format:
usage: date "+format”
Example:
Continued in the next page
date "+%Y-%m-%d %H:%M:%S"
Common Format Codes
1. %Y : Year (four digits)
2. %m : Month (01-12)
3. %d : Day of the month (01-31)
4. %H : Hour (00-23)
5. %M : Minute (00-59)
6. %S : Second (00-59)
Setting the Date and Time
To set the system date and time:
sudo date -s "YYYY-MM-DD HH:MM:SS"
Tips
1. Use date to display or set the system date and time.
2. Customize the output format to suit your needs.
echo 'message' - to display a message to the terminal or to a file
man (Manuel) - gives you the chance to view the Manuel about a command in Linux e.g. =>
man ls
shell Meta characters = special characters recognized by the shell e.g.
" * “(dir. *.exe) meaning display all file with the mention/typed extensions in WINDOWS
(ls *.exe) meaning display all file with the mention/typed extensions in LINUX
"?" matches any single character in WINDOWS or LINUX e.g.
=> ls ?????.txt
Continued in the next page
("????") they are also called strings characters they let you specify the amount or count of
words to run against the directory in search of a file or a folder
when you typed in "?" more than an existing character you will be prompted with an error
message as
"ls: cannot access ????????.txt: No such file or directory"
">" it's for redirecting the contents of a command to an output e.g.
Echo=>
echo "hello, Linux">[Link] this means we’re sending the text hello, Linux into a file called
[Link]
another example is using the ls command => ls >[Link] will output our listing
into a file called [Link]
cat =>
the "cat" command can be used to verify the file written to the file you created e.g.
cat [Link]
More and Less commands
This are type of command use to view large file one page at a time
More=>
More /etc/passwd
With the more command you have the chance to view page by page and also letting you
know of how much of info you have remaining in percentages increasing from the lowest to
(100%)
Less=>
Less /etc/passwd
Wc=>
The wc commands let you know the number of text counts available in a file
Continued in the next page
Example of a two different file one and empty file and the other a file containing some texts
The picture below shows a file that has some contents in it and the other has no contents in
it
Grep=>
The use of grep let you scan through a text file and let you grab a text from a line from it
e.g.
grep root /etc/passwd
grep -v root /etc/passwd. The -v let you have the results in a reverse manner
or
cat /etc/passwd |grep root
Egrep=>
egrep ‘run|root’ /etc/passwd this let use to grab two different words that matches our search
from the passwd configuration file
Touch=>
Touch let you to create files in Linux e.g.
touch [Link] [Link] [Link]
depending of the type of file you are creating you will need to specify an extension name
example we did above is the .txt file extension for a text file
Link file in Linux
Continued in the next page
Link file in Linux means you re creating a short cut file to another which meaning there re
linked to another, it allows you to provide multiple location for a single file
Types of files : Hard Link File and addition name for an existing file both the original file and
the and the hard link file share the same inode
Ls -i will display an inode number of a file
ls -li let you combine the listing with the inode number of a file
SYMBOLIC LINKS
What is a Symbolic Link?
A symbolic link is a file that points to another file or directory, allowing multiple names for
the same file.
Notice!!! In this Example we are going to create a newly created file to perform this action
Using touch: e.g. touch [Link] => this creates a text file with the extension .txt when you
omit the .txt it means you have created a file without an extension (.txt)
Creating a Symbolic Link
Use the ln command with the -s option:
ln -s target_file link_name
ln [Link] myfile_link.txt to create a symbolic link file
- target_file is the original file
- link_name is the symbolic link
Example
Create a symlink to a file:
ln -s /path/to/original/[Link] link_to_file
Continued in the next page
Create a symlink to a directory:
ln -s /path/to/original/directory link_to_directory
Benefits of creating symbolic link file (symlink)
1. Convenience: Access files or directories from multiple locations.
2. Flexibility: Update the target file or directory without affecting the symlink.
Common Use Cases of symbolic Link files
1. Shortcuts: Create shortcuts to frequently used files or directories.
2. Versioning: Manage different versions of files or directories.
Removing a Symbolic Link
Use the rm command:
rm link_name
This removes the symlink, not the target file.
any changes made to a linked file affects the original or linked file
SOFT LINK (symbolic link)
To create a softlink (symbolic link) in Linux we use the commands:
ln -s target_file link_name
Example
ln -s /path/to/original/[Link] softlink_to_file
Explanation
- ln is the command for creating links
- -s option specifies a symbolic link (softlink)
- target_file is the original file
- link_name is the name of the softlink
Continued in the next page
Tips (important things to know when creating symbolic or soft link
1. Use absolute paths for target_file to avoid broken links.
2. Softlinks can point to files or directories.
3. Removing the softlink doesn't affect the target file
What they Do:
They pointer to another file
They do not have the same inode number from the original file
deleting a hard link file does not delete the soft link file
ln -s [Link] mytest_soft to create a soft link file
you might be wondering as I am right now that what’s the big difference between the
symbolic and the soft link file, there are no difference they are just the same thing with
difference name
Symbolic link and soft link are often used interchangeably in Linux. They refer to the same concept: a file that points to another
file or directory
Key Points
1. Same concept: Symbolic link and soft link are synonymous.
2. *Created with ln -s*: Both terms refer to links created using the ln command with the -s option.
Terminology
1. Symbolic link: More formal or technical term.
2. Soft link: Informal or colloquial term.
CONGRATULATION YOU MADE IT TO THE BOTTOM
END OF PAGES THANKS FOR READING AND PRACTICE, IF YOU HAPPEN TO COME ACROSS ANY DATA THAT YOU WILL
LIKE US TO SHARE AMONG THE GROUP YOU ARE WELCOME TO COME ABORD WITH IT THANKS