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

[Windows] : Deleting Orphaned DFS Share

Often stuck with an orphaned shared folder?

I did, many times. Moreover when I go ahead and try to delete it, I am hit with an error message saying “The share must be removed from the distributed file system before it can be deleted”

capture

There is an easy way out:

Either find the registry entry for that DFS under HKEY_LOCAL_MACHINESOFTWAREMicrosoftDFSRootsDomain and delete the key named with the DFS name.

OR

If you in love with command-line like me, run the command
dfsutil /clean /server:<server-name> /share:<dfs-root-name>

The next step is to go to services and restart the service called “Server”. “DFS Namespaces” service is dependent on it, so go ahead and accept the prompt that says this will restart DFS Namespaces.

Now go back to the share and remove it without any problems.

 

[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”

Powered by WordPress.com.

Up ↑