Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Monday, November 14, 2016

Display Information About the CPU and Processing Unit on Linux

To display information about the CPU architecture of a Linux system lscpu command is used.

The man page of lscpu says,

lscpu gathers CPU architecture information from sysfs and /proc/cpuinfo. The command output can be optimized for parsing or for easy readability by humans. The information includes, for example, the number of CPUs, threads, cores, sockets, and Non-Uniform Memory Access (NUMA) nodes. There is also information about the CPU caches and cache sharing, family, model, bogoMIPS, byte order, and stepping.

Options that result in an output table have a list argument. Use this argument to customize the command output. Specify a comma-separated list of column labels to limit the output table to only the specified columns, arranged in the specified order. See COLUMNS for a list of valid column labels. The column labels are not case sensitive.

Not all columns are supported on all architectures. If an unsupported column is specified, lscpu prints the column but does not provide any data for it.


lscpu command is very easy to use. To use lscpu, just run "lscpu" on the terminal.

lscpu

Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                1
On-line CPU(s) list:   0
Thread(s) per core:    1
Core(s) per socket:    1
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 78
Model name:            Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
Stepping:              3
CPU MHz:               2399.996
BogoMIPS:              4799.99
Hypervisor vendor:     KVM
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              3072K
NUMA node0 CPU(s):     0
Flags:                 fpu vme de pse tsc msr pae mce cx8
apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr 
sse sse2 syscall nx rdtscp lm constant_tsc rep_good 
nopl xtopology nonstop_tsc pni pclmulqdq monitor ssse3 
cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave 
avx rdrand hypervisor lahf_lm abm 3dnowprefetch rdseed clflushopt

Thursday, November 3, 2016

Find the IP Address of a Specific Network Interface on Linux

To Find the IP Address of a specific network interface on Linux, use the following command,

sudo ip addr show enp0s3
2: enp0s3:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:45:4e:87 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic enp0s3
       valid_lft 85650sec preferred_lft 85650sec
    inet6 fe80::a00:27ff:fe45:4e87/64 scope link 
       valid_lft forever preferred_lft forever

Here enp0s3 is the network interface that I want to see the address of.

The output shows that, enp0s3 has an ipv4 address of 10.0.2.15 and an ipv6 address of fe80::a00:27ff:fe45:4e87



Saturday, October 29, 2016

Create a Directory using C on Linux

To create a directory on Linux using C, take a look at the following code.

#include <stdio.h>
#include <sys/stat.h>

int main(void) {
    char *foldername = "test_dir";

    int status = mkdir(foldername, S_IRUSR | S_IWUSR | S_IXUSR);

    if(status == 0) {
        printf("Folder successfully created.\n");
    } else {
        printf("Error: Folder creation failed.\n");
    }

    return 0;
}

How it works:

First I declared a variable foldername. This variable stores the name of the folder that I want to create.

Then I used the mkdir(foldername, permission) library functions from sys/stat.h. This function will return 0 if a folder is created or -1 on failure. I stored the return value on a variable status.

Then I checked the status variable to see if a folder is created(status == 0) or not(status == -1).


Here is used, S_IRUSR | S_IWUSR | S_IXUSR as permission. It means, the newly created directory will have read, write, and execute permission of the owner of the directory.

You can find a whole list of permission constants here. I am writing some common easy to remember ones here.


S_IRUSR - Read permission of the owner of the directory.
S_IWUSR - Write permission of the owner of the directory.
S_IXUSR - Execute permission of the owner of the directory.
S_IRGRP - Read permission of the group.
S_IWGRP - Write permission of the group.
S_IXGRP - Execute permission of the group.
S_IROTH - Read permission to others.
S_IWOTH - Write permission to others.
S_IXOTH - Execute permission to others.

Saturday, October 15, 2016

Unlock User Account (Enable User Login) on Linux

To unlock a user account that has been locked on linux, you can use the passwd command.

The command is,

sudo passwd -u username

For example, to unlock the user 'linda', so 'linda' can login to the system again,

sudo passwd -u linda
Unlocking password for user linda.
passwd: Success

Now you can try to login as 'linda' and you will see that login is working again.

Disable User Login (Lock Password) on Linux

To lock a user account on linux, you can use the passwd command.

The command is,

sudo passwd -l username

For example, to lock the user 'linda', so 'linda' can not login to the system anymore,

sudo passwd -l linda
Locking password for user linda.
passwd: Success

Now you can try to login as 'linda' and you will see that you login is disabled.

Thursday, October 13, 2016

See The Users that have Running Processes on Linux System

Hi,

Today I am gonna write about how to see the users on your Linux system that are running some processes.

I have a YouTube video about this post. Check it out if you wish.

YouTube : See The Users that have Running Processes on Linux System



The command is,

sudo ps aux | awk '{print $1}' | sort | uniq | grep -v USER

Explanation

sudo ps aux is used to list the running processes of the system.

awk '{print $1}' is used to print only the first column from the output of sudo ps aux

sort is used to sort the output.

uniq is used to get only the unique lines.

grep -v USER is used to remove the line that contains the field name USER.

Thank you for the visit. :-)