Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 3234

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 61k
Author
Asked: November 26, 20242024-11-26T12:50:05+00:00 2024-11-26T12:50:05+00:00

Complete Linux Essentials!

  • 61k

The Prompt

Open up the terminal, We see our prompt:

prompt

which includes your username@machinename, followed by a ~ and then a $, ~ represents home directory and $ represents that you are a regular user and not a super user.

Understanding the command structure

command -options arguments

  • -options: modifies the command behaviour, enables us to provide single or multiple options for a command.

  • arguments: many commands accepts arguments, these are the things that the command acts upon or uses.

Note: Commands are case sensitive.

Example:
sort -r file.txt, -r is an option(s) and file.txt is an argument.

Man Pages

Reference Manual page for commands, we can view the details of a command by running
man touch

Types of commands

  1. External commands: An executable program, usually stored in /bin, /usr/bin, or /usr/local/bin, Every command we run is a file on the system, its a compiled binary file.
    Note: you can see where your command file is stored by running which <commandname>

  2. Internal commands: A built in shell command, these are part of the shell (bash) and are not part of executable files, the shell executes them directly.

  3. Shell Functions: Shell functions are blocks of code that group commands together in a reusable way, they allow users to define their own commands within scripts.

  4. Alias: It is a shortcut for a command or a series of command, this can be defined in terminal session (temporary) or in .bashrc file (permanent).

Redirection

redirection

Redirection is the process of routing the standard input, standard output and standard error into a file or a program.

Each stream (input, output, error) gets its own numeric descriptor, standard input=0, standard output=1 and standard error=2.

  1. Redirecting the standard input: command < input.txt, contents of the file will act as the standard input and will be redirected to the command.

  2. Redirecting the standard output: if you run ls -l > files.txt, the contents will be stored in files.txt.

  3. Redirecting the standard error: cat unknownfile 2> error.txt, here, 2> is the standard error redirection operator, the contents will be stored in error.txt.

Redirecting standard output and standard error to the different VS same file using numeric descriptor.
ls docs > output.txt 2> output.txt AND ls docs > output.txt 2>&1

Absolute VS Relative Path

  • Absolute Path: This starts from ROOT(/) directory, /home/user1/Desktop/file.txt which has the complete path route.

  • Relative Path: Assuming we are in /home/user1/Desktop/ directory already, we can navigate to a folder called tests by running cd tests, this is because this is already in relation to our current working directory, and doesn't need an absolute reference.

Symbolic links

ln -s /your/long/path ~/shortcut

  • ln is the command to create links.
  • -s specifies it should be symbolic (or soft)
  • /your/long/path is the full directory path you want the shortcut for
  • ~/shortcut is the location and name for your symbolic link, which you can adjust as needed.

Once created, you would navigate to your long path directory by using your shortcut cd ~/shortcut
Symbolic links remain persistent accross sessions, In order to remove the shortcuts, rm ~/shortcut.

File and Directories Handling

Creating files and Folders

  • touch colors.txt will create colors.txt.

  • mkdir templates will create a folder called templates.

Copying, Moving, and Deleting

  • cp colors.txt /home/user1/Desktop/new/ will copy the colors.txt file to the specified path, and cp new/ /home/user1/Desktop/updated_new/, will copy entire folder contents into the updated_new folder.

  • mv colors.txt /home/user1/Desktop/new/ will move the colors.txt file to the specified path, and mv new/ /home/user1/Desktop/updated_new/, will move the entire folder contents into the updated_new folder.

  • rm colors.txt will delete colors.txt

  • rm -d <foldername>, deletes empty directories.

  • rm -r <foldername>, deletes folder and subfolder's in recursive mode. use -f option to delete everything by recursive force.

Listing Directories

ls displays the contents of a folder, -l option helps us to view it in long form, -la helps us to see the longform + hidden files and -lah option shows the human readable format.

More Useful Commands

  • pwd, prints the current working directory.

  • cd <dirname>, changes the current working directory to the mentioned directory.

  • cat <filename>, Displays the contents of a file on the terminal.

  • more <filename>, Views a file, page by page.

  • less <filename>, Similar to more, but allows backward scrolling.

  • nano <filename>, text editor that enables editing of a file.

  • whoami, shows the username of the current user.

Permissions

These are of three types: read, write and execute, the numeric descriptors for them are read=4, write=2 and execute=1, the file permissions for a file or folder can be viewed by listing the content of the diretories, ls -l, the first column displays the file permissions and the third column is user and fourth column is the group.

File Permissions

What is Owner, Group and World?

  • User(u): there can be multiple users on the system.

  • Group(g): Users can belong to a group which are given access to a particular files or folder.

  • World(o): Anyone apart from owner and not in group.

Altering Permissions

chmod <permissiontype>
for example, we can change the users permissions for a file or a folder by saying, chmod u+rw file.txt (change mode for user, add permissions read and write for the file named file.txt)

or we can do it numerically, giving all read, write and execute access for all of the roles by saying chmod 777 file.txt (change mode, give read, write and execute access for all of the roles).

Environment Variables

Shell maintains set of information during a shell session known as the environment, It is just a series of key value pairs separated by equals to sign, that define properties like:

  • Your home directory
  • Your working directory
  • The name of your shell
  • The name of the logged in user

Viewing the Environment

Type printenv in the terminal, to view the environment variables and their current values.

Parameter Expansion

You can print out an environment variable with an dollar sign using echo command, for example,

echo $USER, will print out the current user who is logged in.

Defining Variables

You can define a variable by saying variable=value, for example color=’purple’

Aliases

You can your own commands by using an alias keyword, for example,

alias ll = ‘ls -l’, now you can run ll instead of ls -l, remember setting alias will affect the shell session only, look on how to add it to global config file.

Startup Files

When we login, shell reads information from startup files, First, shell reads from global config file that affects the environment all of the users, Then, shell reads startup files for specific users.

The specific files the shell reads from depends on the type of session, login vs non-login session.

  • For Login Sessions:

/etc/profile : global config for all users.
~/.bash_profile : user’s personal config file.
~/.bash_login : read if bash_profile isn’t found.
~/.profile : used if previous two aren’t found.

  • For Non-Login Sessions:

etc/bash.bashrc : global config for all users

~/.bashrc :specific settings for each user. This is where we can define our own settings and configuration.

Shortcuts

  • ctrl-l : clears the commands in the terminal.
  • ctrl-a : move the cursor in the terminal to the beginning of the line.
  • ctrl-e : to move the cursor to the end of the line.
  • ctrl-f : to move the cursor forward by one character.
  • ctrl-b : to move the cursor backward by one character.
  • alt-f : to move the cursor forward by one word.
  • alt-b : to move the cursor backward by one word.
  • ctrl-k : to kill the text from the current cursor location until the end of the line
  • ctrl-u : to kill the text from the current cursor location until the beginning of the line.
  • ctrl-y : to retrieve the most recently killed text.
  • history : to see the list of commands we have previously entered, we can see the actual file at ~/.bash_history, run this command if you want to run a specific line from the history, !223 to run the 223rd line from the history.
  • ctrl-r : to enter “reverse-i-search”, as you start typing, bash will search the history and show you the best match.
  • ctrl-w : to kill the word from the current cursor position to the beginning of the word.

Conclusion

This blog defines the necessary linux concepts to get started and to build a foundation.

Thanks for reading, Any Suggestions or Feedback is Highly Appreciated!

beginnersdevopslinuxwebdev
  • 0 0 Answers
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    ES6 - A beginners guide - Template Literals

    • 0 Answers
  • Author

    Understanding Higher Order Functions in JavaScript.

    • 0 Answers
  • Author

    Build a custom video chat app with Daily and Vue.js

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.