Linux Commands, And More Commands

I have posted about commands in the past. I am now ‘rebooting’ that post adding additional commands that I find useful.

File Transfer:

$ scp somefile.txt server:/tmp Secure copies somefile.txt to remote host /tmp folder

$ scp sysadmin@server:/www/*.html /www/tmp Copies *.html files from remote host to current system /www/tmp folder

$ scp -r sysadmin@server:/www /www/tmp Copies all files and folders recursively from remote server to the current system /www/tmp folder

$ rsync -a /home/backup /backup/ Synchronizes source to destination

 

File and Folder Archive:

$ tar cf home.tar home Creates tar named home.tar containing home/

$ tar xf file.tar Extracts the files from file.tar

$ tar czf file.tar.gz files Creates a tar with gzip compression

$ gzip file Compresses the file and renames it to file.gz

 

Networking Stuff:

$ ifconfig -a Display all network ports and ip address

$ ifconfig eth0 Display specific ethernet port ip address and details

$ ip addr show Display all network interfaces and ip address(available in iproute2 package,powerful than ifconfig)

$ ip address add 10.0.0.1 dev eth0 Set ip address

$ ethtool eth0 Linux tool to show ethernet status

$ mii-tool eth0 Linux tool to show ethernet status

$ ping host Sends echo request to test connection

$ whois domain Get who is information for domain

$ dig domain Get DNS information for domain

$ dig -x host Reverse lookup host

$ host google.com Lookup DNS ip address for the name

$ hostname -i Lookup local ip address

$ wget file Download file

$ netstat -tupl Listing all active listening ports(tcp,udp,pid)

$ ssh user@host Connects to host as user

$ ssh -p port user@host Connects to host using specific port

$ telnet host Connects to the system using telnet port

 

Permissions:

$ chmod 777 /data/test.c Sets rwx permission for owner , rwx permission for group, rwx permission for world

$ chmod 755 /data/test.c Sets rwx permission for owner,rx for group and world

$ chown owner-user file Changes the owner of the file

$ chown owner-user:owner-group file-name Changes the owner and group owner of the file

$ chown owner-user:owner-group directory Changes the owner and group owner of the directory

 

Process Management:

$ ps Displays your currently active processes

$ ps aux | grep ‘telnet’ Finds all process id related to telnet process

$ pmap Memory map of process

$ top Display all running processes

$ kill pid Kill process with mentioned pid id

$ killall proc Kill all processes named proc

$ sleep 10 & Sleeps at the background

$ kill ‘JobNumber ‘ Terminates the job

$ jobs Display the jobs

$ pkill processname Send signal to a process with its name

$ bg Resumes suspended jobs without bringing them to foreground

$ fg Brings the most recent job to foreground

$ fg n Brings job n to the foreground

 

Useful File Commands:

$ cd .. To go up one level of the directory tree

$ cd Goes to $HOME directory

$ cd /test Changes to /test directory

$ ls gives the contents of a folder.

$ ls -a gives all the contents of a folder.

$ mkdir FolderName creates the folder FolderName.

$ cd Directory makes the Directory current directory

$ pwd prints the working directory

$ cp ~/Desktop/Berk/backups/science.txt . copy science.txt to the current directory

$ mv backups/science.txt /Desktop/Emi moves science.txt to folder Emi

$ rm temp.txt removes the temp.txt file

$ clear clear screen

$ cat science.txt Display contents of a file on the screen

$ less science.txt Displays on a different page ( type q to close the page)

$ less science.txt and then /name finds the occurences of name

$ head science.txt displays the first ten lines of the file

$ tail science.txt displays the last ten lines of the file

$ tail -20 science.txt displays the last 20 lines of the file

$ grep ‘searchedkeyword’ science.txt searches and finds the keyword in the file.(case sensitive)

$ grep -i SeaRchEdKeyWoRd science.txt case insensitive search

$ grep -i ‘SeaRched Sentence is this one’ science.txt case insensitive search

instead of i we can use;
-n precede each matching line with the line number
-v display those lines that do not match
-c print only the total count of matching lines

$ find -name “*.txt” -print finds the text files in the current directory

$ diff a.txt b.txt gives the different lines

$ wc -w science.txt gives the word count

$ wc -l science.txt gives the line count

$ cat > list1
pear
banana

ctrl+d

creates a list and we can print this list by using:

$ cat list1 command line.

$ cat biglist | grep p | sort gives sorted list elements which include p

$ sort < biglist > sortedlist sorts the biglist and writes it to the sortedlist

$ ls list* outputs the filenames starting with ‘list’

$ ls *list outputs the filenames ending with ‘list’

$ ls ?un outputs the filenames ending with ‘un’ but just one letter. (e.g. sun, gun, bun)

$ man ____ gives information about the command in the underlined section.

$ whatis ____ gives information about the command in the underlined section.

$ ls -l gives detailed information about the gfiles in the directory

u:user
g:group
o:other people
rwx: read write execute
rw: read write
r: read
x: execute

$ chmod u+x TheFile adds writing permission to the user(owner) of TheFile

$ chmod go-rwx biglist to remove read write and execute permissions on the file biglist for the group and others

$ chmod 754 TheFile 7, 5, 4 represents the individual permissions for user, group, other (7:rwx, 5:rx, 4:r)

4 – stands for “read”
2 – stands for “write”
1 – stands for “execute”
0 – no permissions

$ du -s * The du command outputs the number of kilobyes used by each subdirectory.

$ df . The df command reports on the space left on the file system.

$ gzip science.txt Compresses into a gzip file

$ gunzip science.txt.gz De-compresses into the original file

$ tar cvf New.tar addthisfileintotar Create a tar file called New and add this file.

$ tar xvf New.tar Extracts the tar file

$ zcat science.txt.gz reads zipped files without unzipping

$ file * Classifies the files in the current directory ( folder, text, gzip, etc.)

$ name=Berk
$ echo Hello $name Prints ‘Hello Berk’

$ sha1sum FileName | grep e509760917361307015 Compares the checksum of a downloaded file and the calculated one.

$ gpg -c file Encrypts file

$ gpg file.gpg Decrypts file

 

User Related:

$ id Shows the active user id with login and group

$ last Shows last logins on the system

$ who Shows who is logged on the system

$ groupadd admin Adds group “admin”

$ useradd -c “Jermal Smith” -g admin -m sam Creates user “sam” and adds to group “admin”

$ userdel sam Deletes user sam

$ adduser sam Adds user “sam”

$ usermod Modifies user information

 

System Statistics:

$ top Displays the top CPU processes (Ctrl+C to exit)

$ vmstat 2 Displays virtual memory statistics

$ sudo tcpdump -i eth0 Captures all packets flows on interface eth0

$ sudo tcpdump -i eth0 ‘port 80’ Monitors all traffic on port 80 ( HTTP )

$ lsof Lists all open files belonging to all active processes.

$ lsof -u myuser Lists files opened by specific user

$ watch df -h Shows changeable data continuously

 

System Info:

$ uname -a Displays Linux system information

$ uname -r Displays kernel release information

$ uptime Shows how long system running + load

$ hostname Shows system host name

$ hostname -i Displays the IP address of the host

$ last reboot Shows system reboot history

$ date Shows the current date and time

$ cal Shows this month calendar

$ whoami Shows who you are logged in as

 

Hardware Info:

$ dmesg Detected hardware and boot messages

$ cat /proc/meminfo Hardware memory information

$ cat /proc/cpuinfo CPU model information

$ cat /proc/interrupts Lists the number of interrupts per CPU per I/O device

$ sudo lshw Displays information on hardware configuration of the system

$ lsblk Displays block device related information in Linux (sudo yum install util-linux-ng)

$ free -m Displays used and free memory (-m for MB)

$ lsusb -tv Shows USB devices

$ dmidecode Shows hardware info from the BIOS

$ hdparm -i /dev/sda # Shows info about disk sda

$ hdparm -tT /dev/sda # Do a read speed test on disk sda

$ badblocks -s /dev/sda # Test for unreadable blocks on disk sda

 

7 Tips For All New Employees To Read – Dale Carnegie

Sharing is caring. So I am sharing something I received from Dale Carnegie

1. Make A Great First Impression – Before starting, practice what you will say when introducing yourself; think about all of the questions people might ask you and develop your answers. Choose honest, concise responses, but be sure to be friendly. Don’t forget to dress for success and shine your shoes!

2. Get To Know Your Company And The People Of The Company
If you have not done so already, take the time to read up on your company (using the company’s website or industry articles as sources). Once you start gathering more information, observe the work environment and understand everyone’s job and the impact they have on getting things done. Most importantly, don’t get caught up on the company’s gossip.

3. Own Your Mistakes – It is typically expected that a new hire will make a mistake somewhere down the line. Face a blunder head on and ask for help immediately. Learn from it, and ensure that this same problem does not happen again.

4. Know Your Manager – Since your manager will be evaluating you and often makes decisions about your career with regards to promotions, raises, etc., you want to make him or her as happy as possible. Find out how he/she works, what they are most concerned about, and what they expect of you. Don’t forget to pay special attention on how he/she likes to communicate (meetings vs. e-mails) and their overall management style. The bottom line is that you want to create a positive work relationship right from the get-go.

5. Know Your Job And How Your Performance Will Be Graded -Sometimes aspects of a job are a little different than what you thought during the interview. Talk to your manager early on so that you are both on the same page about expectations, how he/she will evaluate your performance, and so on.

6. Do Your Homework – While enthusiasm is wonderful, it is not usually a great idea to rush into a new position and try to make many drastic changes right off the bat. There might be very legitimate reasons that certain policies or practices are in place, and you will look much more competent if you ask questions and do your homework before making big suggestions. You do not want to alienate yourself from your peers by stepping on their toes, especially if the changes you are suggesting have already been tried before or are not even possible.

7. Be Friendly – Never underestimate a good smile. You want everyone at your new job to be on your side. You do not necessarily need to be everyone’s friend, but you want people to have your back. Also, work is lot easier if you are on friendly terms with those around you.

Executive Summary: Being a new hire is not always fun, but with a little research, patience and diligence, it does not have to be a truly stressful experience. Heed the advice listed above to make the transition to your next job as smooth as possible.

How to Remove Users From the Office 365 Deleted Users

And… its time to purge those 365 deleted users. Although we can wait for the retention policy to do it for us. I wanted to do this “now”.

I had wrote the following steps in the past and thought I would share here.

[Press Start]

To delete the account for one or more users

Sign in to Office 365 with your work or school account.

Go to the Office 365 admin center.

Go to Users > Active Users.

Choose the names of the users that you want to delete, and then select DELETE Delete.

In the confirmation box, select Yes.

Done!

[Pause]

Well, not so fast. The deleted users is not fully gone yet. It takes 30 days after you have deleted the user for it to purge from Office 365. However there is a way to do this faster

[Press Start]

Connect to Exchange Online using the Windows Azure Powershell module.

To connect you enter the following cmdlet’s:

  1. Store your credetials (this is stored in memory): $msolcred = get-credential
  2. Connection to Office 365: connect-msolservice -credential $msolcred

Once connected you can issue the following command to list deleted users:

get-msoluser –returndeletedusers -maxresults 100

To remove a deleted user permanently:

remove-msoluser –userprincipalname UID@UPN.com -RemoveFromRecyclebin

If you had multiple users, the following cmdlet would work to remove all deleted users recycle bin:

get-msoluser –returndeletedusers -maxresults 100 | remove-msoluser -removefromrecyclebin -force

That’s it… Your done. Good Luck

Original Post of mine can be found here

QOTD: “for whom the bell tolls”


“Any man’s death diminishes me, because I am involved in Mankind; And therefore never send to know for whom the bell tolls; it tolls for thee.” – John Donne

Quick How To Share a Document with OneDrive for Business


You can share file(s): Documents and such with Onedrive for Business

1.      In the file list, right-click a document, or select a document and then select Share.

2.      Select Get a link.

3.      Choose who to share with, and if they can view or edit the file.

4.      To share with people inside your organization, choose:

5.      View link – account required – people inside your organization can view, copy, or download the document.

6.      Edit link – account required – people inside your organization can edit, copy, or download the document.

7.      To share with people outside your organization, choose:

8.      View link – no sign-in required – people outside your organization can view, copy, and download the document.

9.      Edit link – no sign-in required – people outside your organization can edit, copy, and download the document.

10.  For external links, select SET EXPIRATION, and choose when you want the link to expire.

11.  Click Copy and paste the link in an email or post it.

Note: Links created that don’t require a sign-in can be opened by anyone, so make sure the content can be shared publicly. Consult your Corporate Information Security Policy and IT if needed.

Note: Sharing of folders is not possible at this time.

Exchange Remote PowerShell Broken in Windows 10 Anniversary Update

So you updated to Windows 10 Anniversary and now have found yourself unable to connect to a remote PowerShell sessions. I noticed this in my management of Exchange Online in Office 365 after upgrading to Windows 10 version 1607 aka Anniversary Edition.

In my attempts to connect, as I have done in the past: http://jermsmit.com/azure-active-directory-module-for-windows-powershell-how-to-connect/ I encountered a error message:

 

Later comparing this with my down-level installs of Windows 10 and Server 2012 R2 this issue does not exist. So what changed?

It seems that the version of PowerShell which was updated may have something to do with this issue. This is when I attempted to run PowerShell in a down-level mode.

This is done by issuing the following command in an elevated command prompt (Run As Administrator): PowerShell.exe -Version 2.0

From this point we can now connect without issue.

Hope this helps

iOS 10 Device Compatibility

Its that time again.  When our hard working friends over at Apple release their new iOS version.  This time its version 10.  The question I asked myself and I am sure many are asking… Will my older devices be compatible to the new OS.

This is what I have found:

iPad’s

  • iPad Pro 12.9-inch
  • iPad Pro 9.7-inch
  • iPad Air 2
  • iPad Air
  • iPad 4th generation
  • iPad 3rd generation
  • iPad 2
  • iPad mini 4
  • iPad mini 3
  • iPad mini 2
  • iPad mini

iPhone’s

  • iPhone 6s
  • iPhone 6s Plus
  • iPhone 6
  • iPhone 6 Plus
  • iPhone SE
  • iPhone 5s
  • iPhone 5c
  • iPhone 5

Source: http://www.apple.com/ios/ios-10/

 

In Place Upgrade Of Windows Server 2008 R2 Standard

If you have a need to upgrade a server running Windows Server 2008 R2 Standard to either the Enterprise, or Datacenter edition, it’s possible to do so online, without re-installing Windows. This not only a simple process, it saves you time.

Open an elevated command prompt and type DISM /Online /Get-CurrentEdition. This returns the current Windows version.

Type DISM /Online /Get-TargetEditions to list the Windows editions to which this server can be upgraded to.

Type DISM /Online /Set-Edition:ServerDataCenter /ProductKey:xxxxxx will upgrade the operating system. All that’s required to complete the upgrade is a reboot.

Done!

Ref Info:

DISM Windows Edition-Servicing Command-Line Options – https://technet.microsoft.com/en-us/library/hh825157.aspx

KMS Client Setup Keys – Link

Office 365: Error is [0x80004005-00000000-00000000]

It would not be a Friday without something.  I got reports from users that they were getting bounce back emails.

Error [0x80004005-00000000-00000000] is referenced in the emails. When logging into the web portal the users have a message that their daily limit of messages recipients has been reached.

The following post shows the list of limitations

 

“Pure Imagination” — RIP, Gene Wilder

Gene Wilder, who regularly stole the show in such comedic gems as “The Producers,” “Blazing Saddles,” “Young Frankenstein,” “Willy Wonka and the Chocolate Factory” and “Stir Crazy,” died Monday at his home in Stamford, Conn. His nephew Jordan Walker-Pearlman said he died of complications from Alzheimer’s disease. He was 83.

Rest in peace old friend, you will love on in memory forever

 

Sang no better than this:

Come with me
And you’ll be
In a world of pure imagination
Take a look
And you’ll see
Into your imagination
We’ll begin
With a spin
Traveling in
The world of my creation
What we’ll see
Will defy
Explanation
If you want to view paradise
Simply look around and view it
Anything you want to, do it
Want to change the world?
There’s nothing to it
There is no
Life I know
To compare with pure imagination
Living there
You’ll be free
If you truly wish to be
If you want to see magic lands
Close your eyes and you will see one
Want to be a dreamer, be one
Anytime you please and please save me one