How to Change Your Hostname on WSL Ubuntu in Less Than 2 Minutes

How to change your hostname on wsl ubuntu

  • Note down your hostname
  • Open /etc/wsl.conf or create the same if it does not exist ($vi wsl.conf)
  • Add the following lines in /etc/wsl.conf

[network]
hostname = yourHostname
generateHosts = false

  • Open /etc/hosts and update
Find all occurences of hostname (e.g. "DESKTOP-ABC222") and replace with the new one (e.g. "yourHostname").

  • Close Ubuntu and re-launch
You could open Windows Terminal or Windows PowerShell run wsl --shutdown to shut down the WSL 2 VM and relaunch it.

check it with $echo "$HOSTNAME"




if you need some help with the UNIX commands, please refer to this page https://aufullstackde.blogspot.com/2023/05/basic-unix-commands.html

Enjoy!

Basic UNIX Commands

Basic UNIX commands

Know more about a cmd use $man command

Directory

  • pwd
Show your Present Working Directory
  • mkdir
Make a directory
  • cd dirname
Change directory
  • cd
Return to your home directory
  • cd ..
Return to the upper directory
  • cd /
Return to the root directory


Finding things

  • ls | grep extension
Will show you all files with the 'extension'

e.g., 
  • ll | grep string
Will show you all files with the 'string'

e.g.,  
  • grep string filename(s)/grep [options] pattern [files]
Looks for the string in the files (txt file typically).

e.g., 

$grep python grep_example.txt

txt file (cat grep_example.txt)

Result:


More options

-c : This prints only a count of the lines that match a pattern
-h : Display the matched lines, but do not display the filenames.
-i : Ignores, case for matching
-l : Displays list of filenames only.
-n : Display the matched lines and their line numbers.
-v : This prints out all the lines that do not matches the pattern
-e exp : Specifies expression with this option. Can use multiple times.
-f file : Takes patterns from file, one per line.
-E : Treats pattern as an extended regular expression (ERE)
-w : Match whole word
-o : Print only the matched parts of a matching line,
 with each such part on a separate output line.

-A n : Prints searched line and nlines after the result.
-B n : Prints searched line and n line before the result.
-C n : Prints searched line and n lines after before the result.

Examples,



File

  • ls
Lists your files
  • ls -l
lists your files in 'long format', which contains lots of useful information, e.g. the exact size of the file, who owns the file and who has the right to look at it, and when it was last modified.
  • ls -a
lists all files, including the ones whose filenames begin in a dot, which you do not always want to see.
There are many more options, for example to list files by size, by date, recursively etc.
  • touch filename
Create a new file

e.g., $touch grep_example.txt
  • rm filename
Delete a file
  • rm -r dir (rmdir dir)
Delete a directory
  • cp filename1 filename2
Copies a file
  • more filename
Shows the first part of a file, just as much as will fit on one screen

Just hit the space bar to see more or q to quit. You can use /pattern to search for a pattern.

More examples https://shapeshed.com/unix-more/

  • chmod options filename 

Lets you change the read, write, and execute permissions on your files. 
The default is that only you can look at them and change them, but you may sometimes want to change these permissions. 
For example, chmod o+r filename will make the file readable for everyone, 
and chmod o-r filename will make it unreadable for others again. 
Note that for someone to be able to actually look at the file the directories it is in need to be at least executable.

More https://www.geeksforgeeks.org/chmod-command-linux/

Other

  • export variable=value (now space before and after =)
$export mytestpath = test123
  • echo $variable
Shows the value of an environment variable

$echo $mytestpath
>>test123
  • clear
cleans screen

  • source filename
You need to source your dotfiles after making changes for them to take effect (or log off and in again)

More Unix commands


https://mally.stanford.edu/~sr/computing/more-unix.html

https://mally.stanford.edu/~sr/computing/basic-unix.html

Naming Conventions in Java (代码规范,命名规则)

 

Naming Convention in Java (代码规范,命名规则)

General rules: 


CamelCase/camelCase (mixed case) 


 CamelCase


camelCase

Ref: https://en.wikipedia.org/wiki/Camel_case

Camel case (sometimes stylized as camelCase or CamelCase, also known as camel caps or more formally as medial capitals) is the practice of writing phrases without spaces or punctuation and with capitalized words. The format indicates the first word starting with either case, then the following words having an initial uppercase letter. Common examples include "YouTube", "iPhone" and "eBay". Camel case is often used as a naming convention in computer programming. It is also sometimes used in online usernames such as "JohnSmith", and to make multi-word domain names more legible, for example in promoting "EasyWidgetCompany.com".

The more specific terms Pascal case and upper camel case refer to a joined phrase where the first letter of each word is capitalized, including the initial letter of the first word. Similarly, lower camel case (also known as dromedary case) requires an initial lowercase letter. Some people and organizations, notably Microsoft, use the term camel case only for lower camel case, designating Pascal case for the upper camel case.

Snake case

snake_case


Snake case (stylized as snake_case) refers to the style of writing in which each space is replaced with an underscore (_) character, and the first letter of each word is written in lowercase. It is a commonly used naming convention in computing, for example for variable and subroutine names, and for filenames. One study has found that readers can recognize snake case values more quickly than camel case.

Why Have Code Conventions

Code conventions are important to programmers for a number of reasons:

  • 80% of the lifetime cost of a piece of software goes to maintenance.
  • Hardly any software is maintained for its whole life by the original author.
  • Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly.
  • If you ship your source code as a product, you need to make sure it is as well packaged and clean as any other product you create.
https://www.oracle.com/java/technologies/javase/codeconventions-introduction.html

  • 一个软件需要花费80%的生命周期成本去维护。   
  • 几乎没有任何软件的整个生命周期仅由其原作者来维护。   
  • 编码规范改善软件的可读性,让工程师更快更彻底地理解新的代码。   
  • 如果你将源代码转变为一个产品,那么您需要确保它和你创建的其它产品一样是干净且包装良好的。

Naming Conventions in Python (代码规范,命名规则)

Naming Convention in Python (代码规范,命名规则)

General rules: 


CamelCase/camelCase (mixed case) 


 CamelCase


camelCase

Ref: https://en.wikipedia.org/wiki/Camel_case

Camel case (sometimes stylized as camelCase or CamelCase, also known as camel caps or more formally as medial capitals) is the practice of writing phrases without spaces or punctuation and with capitalized words. The format indicates the first word starting with either case, then the following words having an initial uppercase letter. Common examples include "YouTube", "iPhone" and "eBay". Camel case is often used as a naming convention in computer programming. It is also sometimes used in online usernames such as "JohnSmith", and to make multi-word domain names more legible, for example in promoting "EasyWidgetCompany.com".

The more specific terms Pascal case and upper camel case refer to a joined phrase where the first letter of each word is capitalized, including the initial letter of the first word. Similarly, lower camel case (also known as dromedary case) requires an initial lowercase letter. Some people and organizations, notably Microsoft, use the term camel case only for lower camel case, designating Pascal case for the upper camel case.

Snake case

snake_case


Snake case (stylized as snake_case) refers to the style of writing in which each space is replaced with an underscore (_) character, and the first letter of each word is written in lowercase. It is a commonly used naming convention in computing, for example for variable and subroutine names, and for filenames. One study has found that readers can recognize snake case values more quickly than camel case.

Featured Posts

SnowPro Badges and Certificates

SnowPro Badges and Certificates Online Verification https://achieve.snowflake.com/profile/richardhou888/wallet

Popular Posts Recommended