Sunday, September 11, 2016

Week 1 - Assignment1 - Linux Commands


1.. Create a new user

login as root : sudo su
enter root’s pwd
command : adduser sahan
command user pwd: passwd sahan
to switch to new user : su sahan
to logout : exit
to see current user : whoami


2.. Reset password of user

*.to change current user’s password
cmd : passwd sahan
then enter current one and new one
*.to change another user’s password
login as root
cmd : passwd <username>


3.. Create a directory

login as root
change directory to home : cd /home
create directory : mkdir my_group

Give permissions

chmod ug+rwx my_group

To see permissions

ls -l


4.. Create a directory called my_user at home and give permissions to user only

method 1-
create directory : mkdir my_group

give permissiosn : chmod 700 my_group

method 2-
create directory : mkdir my_group

give permissiosn : chmod og+rwx my_group


5.. How many network interfaces your computer has..?

*.. Finding network interfaces

terminal : ip addr
or
ip link show

to get count :
*..ip link show | wc -l

wc - print newline, word, and byte counts for each file
to get help:
type = man wc

-l – print the count of new lines

*.. ip -o link show | wc -l

-o = to get exact number of network interfaces.

output each record on a single line, replacing line feeds wit the '\' character. This is convenient when you want to count
records with wc(1) or to grep(1) the output.


6.. Install xmind on your desktop without using yum..?

first installed java

url to refer = https://www.digitalocean.com/community/tutorials/how to-manually-install-oracle-java-on-a-debian-or- ubuntu-vps

set path variables for both jdk and jre in /etc/environment
file

**..when installing java to enter PATHS

gedit /etc/environment PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/jdk/jdk1.8.0_102/bin:/opt/jdk/jdk1.8.0_102/jre/bin/java"
JAVA_HOME="/opt/jdk/jdk1.8.0_102"


installed xmind using terminal (debian packge – not using tar)


7.. How you get first 5 entries of /var/log/messages..?

Linux logs a large amount of events to the disk, where they’re mostly stored in the /var/log directory in plain text. Most log entries go through the system logging daemon, syslogd, and are written to the system log.

To get last five entries=
terminal : tail -5 /var/log/syslog


to enable /var/log/messeges file:
edited /etc/rsyslog.d/50-default.conf file (removed # symbols related to messeges)
then restarted the computer


8.. How you get first 5 entries of /var/log/messages..?

terminal : head -5 /var/log/syslog

*. error occurred – desktop deactivted… try to fix using terminal



9.. How you get log entries of /var/log/messages which printed within today..?

‘find’ command :

find cmd can be used to find directories or files
eg :
Find files older than 31 days and delete them
terminal : find /path/to/search -mtime +31 -delete

*..get log entries of /var/log/messages
cmd - journalctl --since "2 days ago"


10.. How many lines in /var/log/messages?

wc -l /var/log/messages


11.. How many unique lines in /var/log/messages?

sort /var/log/messages | uniq -c | wc -l


12.. Sort directory/file list based on time inside your home directory?

ls -ltr –group-directories-first

group-directories-first = to show first directories by modification date and then files by modification date


13.. Access you friends machine using ssh and copy a file to there.?

SSH, which is an acronym for Secure SHell, was designed and created to provide the best security when accessing another computer remotely. Not only does it encrypt the session, it also provides better authentication facilities, as well as features like secure file transfer, X session forwarding, port forwarding and more so that you can increase the security of other protocols.

An SSH server is a software program which uses the secure shell protocol to accept connections from remote computers. SFTP/SCP file transfers and remote terminal connections are popular use cases for an SSH server. This article compares a selection of popular servers.

To check ssh status : sudo service ssh status
installed ssh : sudo apt-get install openssh-server

first intalled ssh server
apt-get install openssh-server

if needed install ssh client
apt-get install openssh-client
then create new user except hsenid in the server machine
then type : ssh vidushka@10.0.0.18


14.. Copy file which reside on your machine to your one using shell at you machine.?


What is "the shell"?

Simply put, the shell is a program that takes your commands from the keyboard and gives them to the operating system to perform. In the old days, it was the only user interface available on a Unix computer. Nowadays, we have graphical user interfaces (GUIs) in addition to command line interfaces (CLIs) such as the shell.

On most Linux systems a program called bash (which stands for Bourne Again SHell, an enhanced version of the original Bourne shell program, sh, written by Steve Bourne) acts as the shell program. There are several additional shell programs available on a typical Linux system. These include: ksh, tcsh and zsh.

To copy : cp /to/source /to/destination
To move : mv /Source_Path /Destination_Path

man cp


15.. Rename your directory my_group to my_group1..?

cp : mv /home/my_group /home/my_group1

mv can also be used for moving.


16.. How you view partition information..?

We're talking about four main file systems: Ext2/Ext3/Ext4 and Btrfs (see B-Trees) as Ubuntu natives, and FAT32 and NTFS on Windows.

1.cmd : sudo lsblk -f

lsblk -f cmd displays=
NAME FSTYPE LABEL UUID MOUNTPOINT
sda1 vfat ESP F27D-78FF /boot/efi


17.. How you get total sizes of sub directories inside /var using single command?

Cmd : du -h /var

output eg : 4.0K /var/opt
4.0K /var/log/upstart


18.. Change system date to yesterday using command line..?

cmd : date 


19.. Remove directory my_group..?

cmd : rm
rm removes each specified file. By default, it does not remove directories.
cmd : rm -f
can be used to remove directories and contents

cmd : rmdir
remove only empty directories


20.. What are the following utilizations of your desktop.?

cmd : top 

The top program provides a dynamic real-time view of a running system. It can display system summary information as well as a list of processes or threads currently being managed by the Linux kernel.

cmd : ps  
report a snapshot of the current processes.

1..CPU utilizations –

install systat - apt-get install sysstat
type cmd - mpstat

to get cpu usage in percentage -
cmd - echo $[100-$(vmstat|tail -1|awk '{print $15}')]

2..Memory utilizations -

cmd - cat /proc/meminfo

3..Disk utilization -

cmd – df

No comments:

Post a Comment