Search

Me Learning Tech

This is where I write about anything that I learn related to any technology.

[Linux] : Command Line Cheat Sheet

There are literally thousands of commands in Linux and I am not even talking about the custom ones developed by the community for some awesome stuff. I accept that it is impossible (at least for me) to remember all of them.Today I came across this awesome “Linux Cheat Sheet” with all the important command-line Linux commands.

But the question is, do we really need so many commands when we are talking to Tux the Penguin? The answer is of course No.

So which are the commands that I really need to know about to become a Linux Ninja? Today I came across this awesome “Linux Cheat Sheet” with all the important command-line Linux commands (courtesy : Linux Training Academy).

View / Download

 

Advertisements

[JS] : Decimal and Hexadecimal

This is pretty interesting how you can convert not just standard decimal or hexadecimal numbers but any number with base between 2 and 32. Here’s how:

Dec to Hex:

var myDecimalNum = 10;
myDecimalNum.toString(16);

result : a

Hex to Dec:

var myHexNum = "a";
parseInt(myHexNum,16);

result : 10

And not just base 16 (hex), you can do it for any base. Try different bases and have fun.

[LINUX] : chmod & chown : The File & Folder Access Control

chmod and chown are among those popular linux commands.

chmod : To modify access to files and folders by providing read/write/execute permissions.
chown : To change the ownership of a file or folder. Continue reading “[LINUX] : chmod & chown : The File & Folder Access Control”

[LINUX] : useradd & usermod : The Linux User Administration

Adding user to a Linux environment is pretty easy!
Just type useradd followed by username. Example:

useradd anupam

But!! the user cannot login yet, because the password needs to be set.
The password must follow the suggested password rule. To set password, just type passwd followed by username and enter the new password (needs to be executed as root or SU privileges). If you are not a SU then you can only change your password with this command.

You can find the password rules, aging rules etc in the file:

 /etc/login.defs

To modify existing user use the command usermod. It has a lot of options like modifying primary group, supplementary group, lock and unlock user account, move or update user home directory etc. Example, to lock user account:

usermod -L anupam

And finally to delete a user, use the command userdel

Pretty interesting eh!

[LINUX] : man, info & pinfo : The Linux Documentations

In Linux, to get help or to read documentations on a particular command we can use either of the three ways : man, info or pinfo .

The help command man is more popular and gives a concise documentation of how to use a command, whereas the info or pinfo are the GNU documentations which are more detailed.

I personally liked pinfo the most, maybe because I come from a windows background, but I guess I will use man more 😀

To get help with any of these documentation commands, just write the documentation command followed with the command with which you need help. Example:

man date

or

pinfo date

or

info date

[LINUX] : locale & localectl – The Linux Locale Settings

You can get or set the locale settings in a linux environment (tried in fedora) by using the command :

localectl

You can remember it as Locale Control

You can also get more locale information by simply executing the command:

locale

To learn all the possible locale languages type this in terminal:

locale -a

To set locale (to change locale language setting), you can do something like this example:

localectl set-locale LANG=fr_FR.utf8

Also to temporarily to execute any command in a different language, prefix the command with the LANG=<appropriate languagr> <command>. For example:

LANG=fr_FR.utf8 date

To learn more about locale always take help of documentations.

[POWERSHELL] : Get List Of Scheduled Tasks In Properly Formatted CSV

Just when the Powershell Kid thought that CSV is a great way of getting outputs, CSV betrays him.

He realizes this when he tries to create a CSV file which lists all the Scheduled tasks on his computer. He runs this small command which is supposed to get him an output in CSV without any hustle, and it does get him an output in CSV file.

schtasks /query /FO CSV > "C:UsersPKTaskSchedList.csv"

But wait!!. It opens in MS Excel fine, but everything in the file is in a “single” column. This is not how he wanted it. Well, of course, it has a way around, by doing some MS Excel Mumbo Jumbo, but he doesn’t like this way of doing it. So he tries this new hack. Powershell does have its ways to get things done.

#Save this as a file named "TaskSchedList.ps1"

$Scriptpath = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
$tempfile = "$($env:temp)TempTaskSchedList.csv"
$outputFile = "$ScriptpathTaskSchedList.csv"
schtasks /query /FO CSV > $tempfile
Import-csv -Path $tempfile | ?{$_.Taskname -notmatch "TaskName"} | Export-csv -Path $outputFile -NoTypeInformation

And great!! It does wonders!

[POWERSHELL] : Get Path Of Currently Executing Script

Another interesting scripting day for Powershell Kid and suddenly he is stuck at a simple problem. He can’t keep mentioning the full directory path every time explicitly in the script. Because, next minute if he moves the script to some other location, the script fails!! Let’s look into the problem he is facing.

Powershell Kid creates an awesome script which uses few other files for input and output. So his script is saved at

D:My Test ScriptsThe Crazy ScriptCrazyPS.ps1

and the script uses external files for input and output purpose, something like

-----
-----
$inputcontent = Get-Content "D:My Test ScriptsThe Crazy Scriptbininput.txt"
-----
-----
$output >>  "D:My Test ScriptsThe Crazy Scriptbinoutput.txt"

Continue reading “[POWERSHELL] : Get Path Of Currently Executing Script”

[POWERSHELL] : Get-PrinterDetails from Print Servers

Technet

PoshCode.org

 

Introduction

In your server environments sometimes to get the details of printers on a print server people need to log-in to the print server, open MMC console, go to print management, add servers and then get to see the printer details.

This is a Powershell script which is invoked by the batch file in the main folder does that all for you. Running the batch file would give a prompt asking for server name and credentials for the server.

The output produced is a HTML file which opens right after the execution completes. Continue reading “[POWERSHELL] : Get-PrinterDetails from Print Servers”

Powered by WordPress.com.

Up ↑