Linux Archives - Code Snippets https://www.mohamedkadi.com/snippet/category/linux/ Fast Coding without memorizing Wed, 25 Sep 2024 11:21:36 +0000 en-US hourly 1 https://wordpress.org/?v=6.7 216119969 A Beginner’s Guide to Getting System Information on Linux https://www.mohamedkadi.com/snippet/a-beginners-guide-to-getting-system-information-on-linux/ https://www.mohamedkadi.com/snippet/a-beginners-guide-to-getting-system-information-on-linux/#respond Thu, 02 Nov 2023 14:02:35 +0000 https://www.mohamedkadi.com/snippet/?p=113 If you’re new to Linux, you might find it helpful to know how to check various details about your system. From the kernel version to memory usage, Linux offers a range of simple commands to help you gather key information. Whether you’re troubleshooting or just getting to know your machine better, these commands can be […]

The post A Beginner’s Guide to Getting System Information on Linux appeared first on Code Snippets.

]]>
If you’re new to Linux, you might find it helpful to know how to check various details about your system. From the kernel version to memory usage, Linux offers a range of simple commands to help you gather key information. Whether you’re troubleshooting or just getting to know your machine better, these commands can be quite handy.

Here’s a list of the most useful Linux commands to get system information, with a brief explanation of what each does:

1. uname -a: Get Basic System Information

This command gives you an overview of your system’s core details, including the kernel name, version, and other basic info like the machine hardware name and processor type. Think of it as a quick snapshot of your Linux environment.

uname -a

2. lsb_release -a: Find Out Your Linux Distribution

Want to know which Linux distribution you’re running? This command will tell you! It provides specifics like the distributor ID, description, release number, and codename of the distribution.

lsb_release -a

3. hostname: Display Your System’s Hostname

This is a simple command to show the name of your system on the network. It’s helpful for identifying your machine when working in multi-computer environments.

hostname

4. cat /etc/os-release: Check Operating System Details

For a more detailed breakdown of your operating system, this command digs deeper into specifics like the OS name, version, and the system’s overall release info.

cat /etc/os-release

5. cat /proc/version: Get Your Kernel Version

If you’re looking to find out the version of your Linux kernel, this is the command to use. It displays the kernel version along with additional build information.

cat /proc/version

6. lsblk and df -h: Disk and Filesystem Information

To get an overview of your disk and filesystem usage, these two commands are key.

  • lsblk shows you all available block devices on your system in a tree structure.
  • df -h gives a more human-readable format of your file system usage, showing which drives are mounted and how much space is available.
lsblk
df -h

7. free -h: Check Your Memory Usage

This command is great for checking how much memory (RAM) your system is using. The -h flag makes the output more readable by showing values in GB/MB instead of bytes.

free -h

8. lscpu: Get CPU Information

Want to know more about your processor? lscpu will give you details about the architecture, cores, threads, and more.

lscpu

9. lspci: List PCI Devices

This command provides a list of all PCI (Peripheral Component Interconnect) devices, like graphics cards and network adapters, attached to your system.

lspci

10. lsusb: List USB Devices

To see all the USB devices connected to your system, use lsusb. This is particularly helpful when troubleshooting issues with USB peripherals like keyboards, printers, or external drives.

lsusb

11. ifconfig or ip a: View Network Interface Information

Both ifconfig and ip a commands allow you to view details about your network interfaces, including IP addresses, MAC addresses, and status. While ifconfig is more traditional, ip a is the more modern option.

ifconfig
# or
ip a

12. ls /etc/*-release: View Release Information Files

For a quick look at release-related files on your system, this command lists relevant files that contain important OS version details.

ls /etc/*-release

Conclusion

These Linux commands offer a quick and easy way to gather essential information about your system. Whether you’re a beginner just getting comfortable with the terminal or need to troubleshoot system issues, knowing these commands can save you time and effort.

So, fire up your terminal and give them a try!

The post A Beginner’s Guide to Getting System Information on Linux appeared first on Code Snippets.

]]>
https://www.mohamedkadi.com/snippet/a-beginners-guide-to-getting-system-information-on-linux/feed/ 0 113
Mastering File Permissions in Linux: A Comprehensive Guide https://www.mohamedkadi.com/snippet/mastering-file-permissions-in-linux-a-comprehensive-guide/ https://www.mohamedkadi.com/snippet/mastering-file-permissions-in-linux-a-comprehensive-guide/#respond Sun, 28 May 2023 19:52:29 +0000 https://www.mohamedkadi.com/snippet/?p=84 Understanding file permissions in Linux is crucial for effective system administration. In this guide, we will dive into the intricacies of file permissions and demonstrate how to manage them efficiently. Whether you’re a beginner or an experienced user, this article will help you master file permissions in Linux. Exploring File Permissions: Login with user: To […]

The post Mastering File Permissions in Linux: A Comprehensive Guide appeared first on Code Snippets.

]]>
Understanding file permissions in Linux is crucial for effective system administration. In this guide, we will dive into the intricacies of file permissions and demonstrate how to manage them efficiently. Whether you’re a beginner or an experienced user, this article will help you master file permissions in Linux.

Exploring File Permissions:

  • Login with user:
    • To switch to a specific user, use the command: su username
  • List with Search:
    • To list files and directories and search for specific items, use the command: ls -la | grep myquery

Understanding Permission Notations:

  • Change permission:
    • To modify file permissions, use the chmod command followed by the desired permission notation. For example:
      • chmod 777 myFile sets the file permissions to read, write, and execute for the owner, group, and others.
      • chmod u+xwr,g+xwr,o+xwr myFile grants the owner, group, and others execute, write, and read permissions respectively.
  • Permission Notations:
    • Numeric representation:
      • 1: execute
      • 2: write
      • 4: read
    • Symbolic representation:
      • x: execute
      • r: read
      • w: write
    • Owner, group, others, and all:
      • u: owner
      • g: group
      • o: others
      • a: all
    • Modifying permissions:
      • +: add
      • -: remove
      • =: assign

Copying and Managing Permissions:

  • Copying permissions:
    • To copy permissions from one file to another, use the command: chmod --reference=myfile myfile2
  • Creating Directories with Permissions:
    • To create directories and assign permissions simultaneously, use the command: chmod -m 777 myNewDir
  • Creating Symbolic Links:
    • To create symbolic links (shortcuts) to files, use the command: ln -s /root/mydir/myfile mySymbolicLink
    • Use the -f flag to forcefully override existing links: ln -sf /root/mydir/myfile mySymbolicLink
  • Removing Symbolic Links:
    • To remove a symbolic link, use either the unlink or rm command followed by the link name. For example:
      • unlink mySymbolicLink
      • rm mySymbolicLink

Advanced Techniques:

  • Creating Nested Directories:
    • To create a directory along with its children and grandchildren, use the command: mkdir -p granFather/father/son/grandSon
  • Changing Group:
    • To change the group ownership of a file, use the command: chgrp groupname myFile
  • Changing Owner:
    • To change the owner of a file, use the command: chown username myFile
  • Changing Owner and Group:
    • To change both the owner and group of a file simultaneously, use the command: chown username:groupname myfile

Conclusion: Understanding and managing file permissions is essential for maintaining the security and integrity of a Linux system. With the knowledge gained from this comprehensive guide, you can confidently navigate the world of file permissions and ensure proper access control. Remember to exercise caution when modifying permissions to prevent unintended consequences. Happy file management in Linux!

The post Mastering File Permissions in Linux: A Comprehensive Guide appeared first on Code Snippets.

]]>
https://www.mohamedkadi.com/snippet/mastering-file-permissions-in-linux-a-comprehensive-guide/feed/ 0 84
Mastering VIM: Essential Commands and Features for Efficient Text Editing https://www.mohamedkadi.com/snippet/mastering-vim-essential-commands-and-features-for-efficient-text-editing/ https://www.mohamedkadi.com/snippet/mastering-vim-essential-commands-and-features-for-efficient-text-editing/#respond Sun, 28 May 2023 18:47:19 +0000 https://www.mohamedkadi.com/snippet/?p=72 Welcome to our code Snippets post on VIM, the powerful text editor. Uncover essential commands, navigation tips, and advanced features to boost your productivity. From mastering command mode to efficient buffer management and precise text selection with visual mode, we’ve got you covered. Explore window splitting, handling of suspended jobs, executing Linux commands, and optimizing […]

The post Mastering VIM: Essential Commands and Features for Efficient Text Editing appeared first on Code Snippets.

]]>
Welcome to our code Snippets post on VIM, the powerful text editor. Uncover essential commands, navigation tips, and advanced features to boost your productivity. From mastering command mode to efficient buffer management and precise text selection with visual mode, we’ve got you covered. Explore window splitting, handling of suspended jobs, executing Linux commands, and optimizing settings. Upgrade your text editing skills with this comprehensive VIM guide.

Command Mode:
Shift + a: Enters insert mode at the end of the line.w: Write (save changes)
q: Quit
wq: Write and quit
q!: Quit and discard changes
r: Replace character
x: Delete current character
dd: Delete entire line / cut line to be pasted if desired
i: Enters insert mode at the current cursor location
Ctrl + a: Enters insert mode at the end of the file
r file: Places the content of the specified file at the cursor position
%s/old/new/g: Find and replace (g: replace every occurrence of the given word)

Buffers:
e file: Opens the file in a buffer
bp: Moves to the previous buffer
bn: Moves to the next buffer
bd: Deletes the current buffer
badd: Opens a new buffer while staying in the current buffer
enew: Opens a new buffer
ls: Lists all open buffers
b number (e.g., :b 1): Takes you to the buffer with the specified number

Visual Mode:
v: Enters visual mode
yy: Copies the highlighted text
d: Cuts the highlighted text
p: Pastes the copied or cut text
sort u: Sorts the highlighted text in alphabetical order

Navigation:
0: Moves to the beginning of the line
$: Moves to the end of the line
gg: Moves to the top of the file
G: Moves to the bottom of the file

Splits:
split file-name: Splits the window horizontally
sp: Shortcut for split
vsplite file-name: Splits the window vertically
vs: Shortcut for vsplit
Ctrl + w: Switches between two files in command mode

Jobs:
Ctrl + z: Suspends Vim and returns to the terminal
fg: Brings the suspended Vim process to the foreground
fg number (e.g., fg 1, fg 2): Brings the specified suspended process to the foreground

! linux-command: Executes a Linux command in command mode and returns to Vim.

Miscellaneous:
set number: Displays line numbers on the left of each line
set nonumber: Hides line numbers
vim + number file name: Opens the file and moves the cursor to the specified line
vim -o file1 file2: Opens two files with a horizontal split
vim -O file1 file2: Opens two files with a vertical split

The post Mastering VIM: Essential Commands and Features for Efficient Text Editing appeared first on Code Snippets.

]]>
https://www.mohamedkadi.com/snippet/mastering-vim-essential-commands-and-features-for-efficient-text-editing/feed/ 0 72
Essential Linux Commands for Software Developers https://www.mohamedkadi.com/snippet/essential-linux-commands-for-software-developers/ https://www.mohamedkadi.com/snippet/essential-linux-commands-for-software-developers/#respond Tue, 28 Feb 2023 13:26:40 +0000 https://www.mohamedkadi.com/snippet/?p=7 Discover the power of three essential Linux commands: “ls” (listing files and directories), “cd” (navigating through directories), and “chmod” (managing file permissions). Mastering these commands is crucial for efficient software development in Linux environments. Enhance your productivity and streamline your workflow with this concise guide to essential Linux commands. Exploring Directories and Files The “ls” […]

The post Essential Linux Commands for Software Developers appeared first on Code Snippets.

]]>
Discover the power of three essential Linux commands: “ls” (listing files and directories), “cd” (navigating through directories), and “chmod” (managing file permissions). Mastering these commands is crucial for efficient software development in Linux environments. Enhance your productivity and streamline your workflow with this concise guide to essential Linux commands.

  1. Exploring Directories and Files
    • The “ls” Command
      • $ ls: Lists files and directories in the current directory.
      • $ ls alx/: Lists files and directories in the “alx” directory.
      • $ ls -la: Lists files and directories in long format, including hidden files.
    • Understanding File Permissions
      • File Listing Structure:
        • First column: Type of file & permissions
          • -: File
          • d: Directory
          • l: Symbolic link
        • Permissions:
          • r: Read
          • w: Write
          • x: Execute
          • -: No permission
  2. Navigating through Directories
    • Absolute Path Name
      • $ cd /: Changes to the root directory.
      • $ cd ~: Changes to the home directory.
    • Relative Path Name
      • $ cd -: Changes to the previous directory.
  3. Managing File Permissions with “chmod”
    • Symbolic Mode
      • +: Gives permission
      • -: Removes permission
      • =: Sets permission
      • Example: chmod o+w: Gives write permission to others.
    • Absolute Mode
      • u: User/owner
      • g: Group
      • o: Others/rest
      • +: Gives permission
      • -: Removes permission
      • Example: chmod o+w: Gives write permission to others.

The post Essential Linux Commands for Software Developers appeared first on Code Snippets.

]]>
https://www.mohamedkadi.com/snippet/essential-linux-commands-for-software-developers/feed/ 0 7